Skip to content
This repository was archived by the owner on May 10, 2025. It is now read-only.
Open
2 changes: 1 addition & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,6 @@ steps:

---
kind: signature
hmac: 71729a12ae3556e03f924ac95c8a5cd14bb6a3c2d20ef6768fdd1e853397fd22
hmac: 53e23beca546bde246f812a726320210f33d231106cb154a65cc900ecbf7502e

...
77 changes: 76 additions & 1 deletion administrator/components/com_modules/src/Model/ModulesModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\Path;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\Database\DatabaseQuery;
Expand Down Expand Up @@ -178,6 +179,8 @@ protected function _getList($query, $limitstart = 0, $limit = 0)
$listOrder = $this->getState('list.ordering', 'a.position');
$listDirn = $this->getState('list.direction', 'asc');

$positionList = $this->getValidPositions();

// If ordering by fields that need translate we need to sort the array of objects after translating them.
if (in_array($listOrder, array('pages', 'name')))
{
Expand All @@ -201,7 +204,14 @@ protected function _getList($query, $limitstart = 0, $limit = 0)
$this->setState('list.start', 0);
}

return array_slice($result, $limitstart, $limit ?: null);
$result = array_slice($result, $limitstart, $limit ?: null);

foreach ($result as $row)
{
$row->activePosition = in_array($row->position, $positionList);
}

return $result;
}

// If ordering by fields that doesn't need translate just order the query.
Expand All @@ -226,6 +236,11 @@ protected function _getList($query, $limitstart = 0, $limit = 0)
// Translate the results.
$this->translate($result);

foreach ($result as $row)
{
$row->activePosition = in_array($row->position, $positionList);
}

return $result;
}

Expand Down Expand Up @@ -479,4 +494,64 @@ protected function getEmptyStateQuery()

return $query;
}

/**
* Method to get the positions corresponding to a template.
*
* @return array List of all active template's position names.
*
* @since __DEPLOY_VERSION__
*/
public function getValidPositions()
{
$clientId = $this->getState('client_id');
$db = $this->getDbo();

// Get List of Template Style IDs that are used in Menus
$templateStylesQuery = $db->getQuery(true);
$templateStylesQuery->select('DISTINCT ' . $db->quoteName('template_style_id'))
->from($db->quoteName('#__menu'));

$templateStylesQuery->where($this->_db->quoteName('published') . ' = 1')
->where($db->quoteName('client_id') . ' = :clientid');

// Get List of Template Names that are either set as Default or used in a menu
$query = $db->getQuery(true);
$query->select('DISTINCT ' . $db->quoteName('template'))
->from($db->quoteName('#__template_styles'));

$query->where($db->quoteName('client_id') . ' = :client_id')
->where($db->quoteName('home') . ' = 1')
->orWhere($db->quoteName('id') . ' IN (' . $templateStylesQuery . ')')
->bind(':clientid', $clientId, ParameterType::INTEGER)
->bind(':client_id', $clientId, ParameterType::INTEGER);
$db->setQuery($query);
$templateList = $db->loadColumn();

$positions = [];

foreach ($templateList as $templateName)
{
$basePath = $clientId ? JPATH_ADMINISTRATOR : JPATH_SITE;
$path = Path::clean($basePath . '/templates/' . $templateName . '/templateDetails.xml');

if (file_exists($path))
{
$xml = simplexml_load_file($path);

if (isset($xml->positions[0]))
{
foreach ($xml->positions[0] as $position)
{
if (!array_key_exists((string) $position, $positions))
{
$positions[] = (string) $position;
}
}
}
}
}

return $positions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,12 @@
</th>
<td class="d-none d-md-table-cell">
<?php if ($item->position) : ?>
<span class="badge bg-info">
<span class="badge <?php echo $item->activePosition ? "bg-info" : "bg-secondary"; ?>" aria-labelledby="pv-<?php echo $item->id ?>">
<?php echo $item->position; ?>
</span>
<div role="tooltip" id="pv-<?php echo $item->id ?>">
<?php echo $item->activePosition ? Text::_('JGLOBAL_POSITION_VALID') : Text::_('JGLOBAL_POSITION_INVALID');?>
</div>
<?php else : ?>
<span class="badge bg-secondary">
<?php echo Text::_('JNONE'); ?>
Expand Down
5 changes: 4 additions & 1 deletion administrator/components/com_modules/tmpl/modules/modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@
</th>
<td class="small d-none d-md-table-cell">
<?php if ($item->position) : ?>
<a class="js-position-insert btn btn-sm btn-warning w-100" href="#" data-position="<?php echo $this->escape($item->position); ?>" data-editor="<?php echo $this->escape($editor); ?>"><?php echo $this->escape($item->position); ?></a>
<a class="js-position-insert btn btn-sm <?php echo $item->activePosition ? 'btn-warning' : 'btn-danger';?> w-100" href="#" data-position="<?php echo $this->escape($item->position); ?>" data-editor="<?php echo $this->escape($editor); ?>" aria-labelledby="pv-<?php echo $item->id ?>"><?php echo $this->escape($item->position); ?></a>
<div role="tooltip" id="pv-<?php echo $item->id ?>">
<?php echo $item->activePosition ? Text::_('JGLOBAL_POSITION_VALID') : Text::_('JGLOBAL_POSITION_INVALID');?>
</div>
<?php else : ?>
<span class="btn btn-sm btn-secondary w-100"><?php echo Text::_('JNONE'); ?></span>
<?php endif; ?>
Expand Down
2 changes: 2 additions & 0 deletions administrator/language/en-GB/joomla.ini
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,8 @@ JGLOBAL_PAGINATION_RESULTS_DESC="Show or hide pagination summary, for example, &
JGLOBAL_PAGINATION_RESULTS_LABEL="Pagination Summary"
JGLOBAL_PASSWORD="Password"
JGLOBAL_PASSWORD_RESET_REQUIRED="You are required to reset your password before proceeding."
JGLOBAL_POSITION_INVALID="Invalid Position"
JGLOBAL_POSITION_VALID="Valid Position"
JGLOBAL_PERMISSIONS_ANCHOR="Set Permissions"
JGLOBAL_PREVIEW="Preview"
JGLOBAL_PREVIEW_POSITION="<span>Position:</span> %s"
Expand Down
7 changes: 7 additions & 0 deletions administrator/templates/atum/templateDetails.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
<position>toolbar</position>
<!-- used directly in a component and included here so the position will appear in the list of available positions -->
<position>cpanel</position>
<position>cpanel-components</position>
<position>cpanel-content</position>
<position>cpanel-help</position>
<position>cpanel-menus</position>
<position>cpanel-privacy</position>
<position>cpanel-system</position>
<position>cpanel-users</position>
<position>icon</position>
<position>login</position>
<position>customtop</position>
Expand Down
2 changes: 2 additions & 0 deletions api/language/en-GB/joomla.ini
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,8 @@ JGLOBAL_PAGINATION_RESULTS_DESC="Show or hide pagination summary, for example, &
JGLOBAL_PAGINATION_RESULTS_LABEL="Pagination Summary"
JGLOBAL_PASSWORD="Password"
JGLOBAL_PASSWORD_RESET_REQUIRED="You are required to reset your password before proceeding."
JGLOBAL_POSITION_INVALID="Invalid Position"
JGLOBAL_POSITION_VALID="Valid Position"
JGLOBAL_PERMISSIONS_ANCHOR="Set Permissions"
JGLOBAL_PREVIEW="Preview"
JGLOBAL_PREVIEW_POSITION="<span>Position:</span> %s"
Expand Down