Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion administrator/modules/mod_submenu/mod_submenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
true
);

Menu::preprocess($root);
Menu::preprocess($root, Menu::disabledExtensions());

// Render the module layout
require ModuleHelper::getLayoutPath('mod_submenu', $params->get('layout', 'default'));
Expand Down
47 changes: 43 additions & 4 deletions administrator/modules/mod_submenu/src/Menu/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Joomla\CMS\Language\Text;
use Joomla\CMS\Menu\MenuItem;
use Joomla\Component\Menus\Administrator\Helper\MenusHelper;
use Joomla\Database\DatabaseInterface;
use Joomla\Utilities\ArrayHelper;


Expand All @@ -26,16 +27,48 @@
*/
abstract class Menu
{

/**
* Return the disabled extensions so that they can be hidden from the menu
*
* @return array An array of names of disabled extensions
*
* @since 4.0.0
*/
public static function disabledExtensions(): array
{
$db = Factory::getContainer()->get(DatabaseInterface::class);
$query = $db->getQuery(true);

// Prepare the query.
$query->select($db->quoteName('e.element'))
->from($db->quoteName('#__extensions', 'e'))
->where($db->quoteName('e.type') . ' = ' . $db->quote('component'))
->where($db->quoteName('e.client_id') . ' = 1')
->where($db->quoteName('e.enabled') . ' = 0');
$iterator = $db->setQuery($query)->getIterator();

$extensions = [];

foreach ($iterator as $item)
{
$extensions[] = $item->element;
}

return $extensions;
}

/**
* Filter and perform other preparatory tasks for loaded menu items based on access rights and module configurations for display
*
* @param MenuItem $parent A menu item to process
* @param MenuItem $parent A menu item to process
* @param array $disabledExtensions Names of disabled extensions, that shall be removed from the result
*
* @return void
*
* @since 4.0.0
*/
public static function preprocess($parent)
public static function preprocess($parent, array $disabledExtensions = [])
{
$app = Factory::getApplication();
$user = $app->getIdentity();
Expand All @@ -51,6 +84,12 @@ public static function preprocess($parent)

foreach ($children as $item)
{
if ($item->type === 'component' && in_array($item->element, $disabledExtensions, true))
{
$parent->removeChild($item);
continue;
}

$itemParams = $item->getParams();

// Exclude item with menu item option set to exclude from menu modules
Expand Down Expand Up @@ -83,7 +122,7 @@ public static function preprocess($parent)
$item->addChild($c);
}

self::preprocess($item);
self::preprocess($item, $disabledExtensions);
$children = ArrayHelper::sortObjects($item->getChildren(), 'text', 1, false, true);

foreach ($children as $c)
Expand Down Expand Up @@ -191,7 +230,7 @@ public static function preprocess($parent)

if ($item->hasChildren())
{
self::preprocess($item);
self::preprocess($item, $disabledExtensions);
}

// Ok we passed everything, load language at last only
Expand Down