Skip to content

Commit 9bf1dab

Browse files
authored
[5.2] mod_menu php fixes (joomla#44318)
1 parent 3b7660c commit 9bf1dab

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

administrator/modules/mod_menu/src/Menu/CssMenu.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function load($params, $enabled)
132132

133133
// In recovery mode, load the preset inside a special root node.
134134
$this->root = new AdministratorMenuItem(['level' => 0]);
135-
$heading = new AdministratorMenuItem(['title' => 'MOD_MENU_RECOVERY_MENU_ROOT', 'type' => 'heading']);
135+
$heading = new AdministratorMenuItem(['title' => 'MOD_MENU_RECOVERY_MENU_ROOT', 'type' => 'heading', 'class' => 'class:fa fa-notes-medical']);
136136
$this->root->addChild($heading);
137137

138138
MenusHelper::loadPreset('default', true, $heading);
@@ -293,7 +293,7 @@ protected function preprocess($parent)
293293
continue;
294294
}
295295

296-
if (substr($item->link, 0, 8) === 'special:') {
296+
if (!empty($item->link) && substr($item->link, 0, 8) === 'special:') {
297297
$special = substr($item->link, 8);
298298

299299
if ($special === 'language-forum') {
@@ -311,12 +311,10 @@ protected function preprocess($parent)
311311
* processing. It is needed for links from menu items of third party extensions link to Joomla! core
312312
* components like com_categories, com_fields...
313313
*/
314-
if ($option = $uri->getVar('option')) {
315-
$item->element = $option;
316-
}
314+
$item->element = !empty($uri->getVar('option')) ? $uri->getVar('option') : '';
317315

318316
// Exclude item if is not enabled
319-
if ($item->element && !ComponentHelper::isEnabled($item->element)) {
317+
if ($item->element !== '' && !ComponentHelper::isEnabled($item->element)) {
320318
$parent->removeChild($item);
321319
continue;
322320
}
@@ -413,7 +411,7 @@ protected function preprocess($parent)
413411
}
414412

415413
// Exclude if link is invalid
416-
if (\is_null($item->link) || !\in_array($item->type, ['separator', 'heading', 'container']) && trim($item->link) === '') {
414+
if (!isset($item->link) || !\in_array($item->type, ['separator', 'heading', 'container']) && trim($item->link) === '') {
417415
$parent->removeChild($item);
418416
continue;
419417
}
@@ -460,7 +458,7 @@ protected function preprocess($parent)
460458
}
461459

462460
// Ok we passed everything, load language at last only
463-
if ($item->element) {
461+
if (!empty($item->element)) {
464462
$language->load($item->element . '.sys', JPATH_ADMINISTRATOR) ||
465463
$language->load($item->element . '.sys', JPATH_ADMINISTRATOR . '/components/' . $item->element);
466464
}
@@ -492,7 +490,7 @@ protected function preprocess($parent)
492490
*/
493491
public function getIconClass($node)
494492
{
495-
$identifier = $node->class;
493+
$identifier = !empty($node->class) ? $node->class : '';
496494

497495
// Top level is special
498496
if (trim($identifier) == '') {
@@ -518,7 +516,7 @@ public function getIconClass($node)
518516
}
519517

520518
/**
521-
* Create unique identifier
519+
* Increase the counter and return the new value
522520
*
523521
* @return string
524522
*

libraries/src/Menu/AdministratorMenuItem.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,20 @@ class AdministratorMenuItem extends MenuItem
4343
* @since 4.0.0
4444
*/
4545
public $iconImage;
46+
47+
/**
48+
* The class of the menu item
49+
*
50+
* @var string
51+
* @since __DEPLOY_VERSION__
52+
*/
53+
public $class = '';
54+
55+
/**
56+
* The element type of the menu item
57+
*
58+
* @var string
59+
* @since __DEPLOY_VERSION__
60+
*/
61+
public $element = '';
4662
}

libraries/src/Menu/MenuItem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class MenuItem implements NodeInterface
8181
* @var string
8282
* @since 3.7.0
8383
*/
84-
public $link;
84+
public $link = '';
8585

8686
/**
8787
* The type of link

0 commit comments

Comments
 (0)