Skip to content

Commit

Permalink
Use the injected application in the menu module
Browse files Browse the repository at this point in the history
  • Loading branch information
laoneo committed Oct 29, 2018
1 parent 6403a9a commit 50276f1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
38 changes: 29 additions & 9 deletions administrator/modules/mod_menu/Menu/CssMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

defined('_JEXEC') or die;

use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Menu\MenuHelper;
use Joomla\CMS\Menu\Node;
Expand Down Expand Up @@ -57,6 +57,27 @@ class CssMenu
*/
protected $enabled;

/**
* The application
*
* @var bool
*
* @since __DEPLOY_VERSION__
*/
protected $application;

/**
* CssMenu constructor.
*
* @param CMSApplication $this->applicationlication The application
*
* @since __DEPLOY_VERSION__
*/
public function __construct(CMSApplication $application)
{
$this->application = $application;
}

/**
* Get the current menu tree
*
Expand Down Expand Up @@ -171,7 +192,7 @@ public function renderSubmenu($layoutFile)
*/
protected function check($items, Registry $params)
{
$me = Factory::getUser();
$me = $this->application->getIdentity();
$authMenus = $me->authorise('core.manage', 'com_menus');
$authModules = $me->authorise('core.manage', 'com_modules');

Expand All @@ -180,7 +201,6 @@ protected function check($items, Registry $params)
return false;
}

$app = Factory::getApplication();
$types = ArrayHelper::getColumn($items, 'type');
$elements = ArrayHelper::getColumn($items, 'element');
$rMenu = $authMenus && !in_array('com_menus', $elements);
Expand All @@ -189,7 +209,7 @@ protected function check($items, Registry $params)

if ($rMenu || $rModule || $rContainer)
{
$recovery = $app->getUserStateFromRequest('mod_menu.recovery', 'recover_menu', 0, 'int');
$recovery = $this->application->getUserStateFromRequest('mod_menu.recovery', 'recover_menu', 0, 'int');

if ($recovery)
{
Expand Down Expand Up @@ -224,7 +244,7 @@ protected function check($items, Registry $params)
$menutype = $table->get('title', $menutype);
$message = Text::sprintf('MOD_MENU_IMPORTANT_ITEMS_INACCESSIBLE_LIST_WARNING', $menutype, implode(', ', $missing), $uri);

$app->enqueueMessage($message, 'warning');
$this->application->enqueueMessage($message, 'warning');
}

return false;
Expand All @@ -242,14 +262,14 @@ protected function check($items, Registry $params)
protected function preprocess($items)
{
$result = array();
$user = Factory::getUser();
$language = Factory::getLanguage();
$user = $this->application->getIdentity();
$language = $this->application->getLanguage();

$noSeparator = true;

// Call preprocess for the menu items on plugins.
// Plugins should normally process the current level only unless their logic needs deep levels too.
Factory::getApplication()->triggerEvent('onPreprocessMenuItems', array('com_menus.administrator.module', &$items, $this->params, $this->enabled));
$this->application->triggerEvent('onPreprocessMenuItems', array('com_menus.administrator.module', &$items, $this->params, $this->enabled));

foreach ($items as $i => &$item)
{
Expand Down Expand Up @@ -289,7 +309,7 @@ protected function preprocess($items)
}

// Exclude Mass Mail if disabled in global configuration
if ($item->scope === 'massmail' && (Factory::getApplication()->get('massmailoff', 0) == 1))
if ($item->scope === 'massmail' && ($this->application->get('massmailoff', 0) == 1))
{
continue;
}
Expand Down
10 changes: 2 additions & 8 deletions administrator/modules/mod_menu/mod_menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,12 @@

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Helper\ModuleHelper;
use Joomla\Module\Menu\Administrator\Menu\CssMenu;
use Joomla\Registry\Registry;

/** @var Registry $params */
$lang = Factory::getLanguage();
$user = Factory::getUser();
$input = Factory::getApplication()->input;
$enabled = !$input->getBool('hidemainmenu');
$enabled = !$app->input->getBool('hidemainmenu');

$menu = new CssMenu;
$menu = new CssMenu($app);
$menu->load($params, $enabled);

// Render the module layout
Expand Down
2 changes: 1 addition & 1 deletion administrator/modules/mod_menu/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
HTMLHelper::_('script', 'vendor/metismenujs/metismenujs.min.js', ['version' => 'auto', 'relative' => true]);
HTMLHelper::_('script', 'mod_menu/admin-menu.min.js', ['version' => 'auto', 'relative' => true], ['defer' => true]);

$doc = \Joomla\CMS\Factory::getDocument();
$doc = $app->getDocument();
$direction = $doc->direction === 'rtl' ? 'float-right' : '';
$class = $enabled ? 'nav flex-column main-nav ' . $direction : 'nav flex-column main-nav disabled ' . $direction;

Expand Down

0 comments on commit 50276f1

Please sign in to comment.