Skip to content

[4.0] Hide disabled components in mod_submenu#32555

Merged
wilsonge merged 5 commits intojoomla:4.0-devfrom
alikon:patch-81
Mar 5, 2021
Merged

[4.0] Hide disabled components in mod_submenu#32555
wilsonge merged 5 commits intojoomla:4.0-devfrom
alikon:patch-81

Conversation

@alikon
Copy link
Contributor

@alikon alikon commented Mar 1, 2021

Pull Request for Issue #32456.

Summary of Changes

don't show items from disabled component in mod_submenu

Testing Instructions

see #32456.

Actual result BEFORE applying this Pull Request

see #32456.

Expected result AFTER applying this Pull Request

no items from disabled components are shown

alterrnative to #32539

let's see how many 👎 i got 🤣

@Fedik
Copy link
Member

Fedik commented Mar 1, 2021

this actually looks much better than #32539
because ComponentHelper already have a pre-loaded list of available components.


foreach ($children as $item)
{
if (!ComponentHelper::isEnabled($item->element))
Copy link
Member

@Fedik Fedik Mar 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you also need to check the $item type to be a component, because there may be a spacers or something else.
if I right remember

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, I hope 😄
need to test

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about if ($item->type === 'component' ...
but I do not remember how it exactly there, need to check, later


foreach ($children as $item)
{
if (!empty($item->element) && (!ComponentHelper::isEnabled($item->element)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change the code to

if ($item->element && !ComponentHelper::isEnabled($item->element))

It is a bit easier to read, same with the code in mod_menu https://github.com/joomla/joomla-cms/blob/4.0-dev/administrator/modules/mod_menu/src/Menu/CssMenu.php#L313

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is not done yet. You still have unnecessary ( and ). Please change it exactly to:

if ($item->element && !ComponentHelper::isEnabled($item->element))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alikon You still have unnecessary bracket ( and ) in the code as I said. The code should be

if ($item->element && !ComponentHelper::isEnabled($item->element))

The current code is:

if ($item->element && (!ComponentHelper::isEnabled($item->element)))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah my bad didn't look at bracket

@Fedik
Copy link
Member

Fedik commented Mar 2, 2021

btw, we have similar in mod_menu also 😉

// Exclude item if is not enabled
if ($item->element && !ComponentHelper::isEnabled($item->element))
{
$parent->removeChild($item);
continue;
}

so all should be good

@richard67 richard67 changed the title less code [4.0] Hide disabled components in mod_submenu Mar 2, 2021
@richard67
Copy link
Member

@alikon I was so free to change the title for you so we later have a better commit message when merging the PR.

@particthistle
Copy link
Member

particthistle commented Mar 2, 2021

I have tested this item 🔴 unsuccessfully on abd61d4

Before applying patch, "Manage" list on System Dashboard had 9 items:
Extensions, Languages, Content Languages, Language Overrides, Content Security Policy, Plugins, Redirects, Site Modules, Administrator Modules

After applying patch, without turning off any components, some items disappeared:
Languages, Content Languages, Language Overrides

It seems these three Language related items are not following the same configuration as the other items in the list.

As Language component is a protected one, it can't be disabled, but I'm not sure why it's not otherwise appearing.

Aside from the Language items, the PR works as expected when I turned off either CSP or Redirects as two items available to disable in that dashboard module.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/32555.

@joomdonation
Copy link
Contributor

@particthistle I think the error here is not related to this PR. I don't understand how menu presets work, but someone familiar with that concept should check https://github.com/joomla/joomla-cms/blob/4.0-dev/administrator/components/com_menus/presets/system.xml#L127-L149 to see why element="com_language", not element="com_languages" (I think it is typos). One that issue is fixed, the error you reported here won't happen.

@richard67
Copy link
Member

@particthistle I think the error here is not related to this PR. I don't understand how menu presets work, but someone familiar with that concept should check https://github.com/joomla/joomla-cms/blob/4.0-dev/administrator/components/com_menus/presets/system.xml#L127-L149 to see why element="com_language", not element="com_languages" (I think it is typos). One that issue is fixed, the error you reported here won't happen.

@joomdonation @particthistle Who wants to make a PR?

not com_language
@alikon
Copy link
Contributor Author

alikon commented Mar 2, 2021

better to do it in this pr imho
please test again

@particthistle
Copy link
Member

I have tested this item ✅ successfully on 9511451

All good this time around.

Glad it was something easy for you to resolve @alikon as I wouldn't have known where to start to fix that up.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/32555.

@toivo
Copy link
Contributor

toivo commented Mar 3, 2021

I have tested this item ✅ successfully on 9511451

Tested successfully in Beta8-dev of 3 March in Wampserver 3.2.4 using PHP 8.0.2.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/32555.

@richard67
Copy link
Member

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/32555.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Mar 3, 2021
@wilsonge wilsonge merged commit 5e57dae into joomla:4.0-dev Mar 5, 2021
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Mar 5, 2021
@wilsonge
Copy link
Contributor

wilsonge commented Mar 5, 2021

LGTM. Nice work everyone!

@wilsonge wilsonge added this to the Joomla 4.0 milestone Mar 5, 2021
@alikon alikon deleted the patch-81 branch March 5, 2021 14:48
dgrammatiko pushed a commit to dgrammatiko/joomla-cms that referenced this pull request Mar 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants