Skip to content
This repository was archived by the owner on May 10, 2025. It is now read-only.
Open
68 changes: 67 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,55 @@ 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');
$positions = [];

$db = $this->getDbo();
$query = $db->getQuery(true);
$query->select(
[
$db->quoteName('template'),
]
)
->from($db->quoteName('#__template_styles'));

// Filter the active template
$query->where($db->quoteName('home') . ' = 1')
->where($this->_db->quoteName('client_id') . ' = :client_id')
->bind(':client_id', $clientId, ParameterType::INTEGER);;
$db->setQuery($query);

$templateName = $db->loadObjectList()[0]->template;

if (isset($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)
{
$positions[] = (string) $position;
}
}
}
}

return $positions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
</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"; ?>">
<?php echo $item->position; ?>
</span>
<?php else : ?>
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