Description
Preconditions
- Magento 2.2.0-dev is installed (bdb0464 at the time of writing)
- Any
menu.xml
adds menu items with dependency to
- module that is not installed
- config value that evaluates to false
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
<menu>
<add id="Foo_MenuItemDependencies::dependencies"
title="Menu Item Dependencies"
translate="title"
module="Foo_MenuItemDependencies"
sortOrder="10"
parent="Magento_Backend::system"
resource="Foo_MenuItemDependencies::dependencies"
/>
<add id="Foo_MenuItemDependencies::module_dependency"
title="Depends On Module"
module="Foo_MenuItemDependencies"
sortOrder="10"
resource="Foo_MenuItemDependencies::dependencies"
parent="Foo_MenuItemDependencies::dependencies"
action="foo/module"
dependsOnModule="Foo_Bar"
/>
<add id="Foo_MenuItemDependencies::config_dependency"
title="Depends On Config"
module="Foo_MenuItemDependencies"
sortOrder="20"
resource="Foo_MenuItemDependencies::dependencies"
parent="Foo_MenuItemDependencies::dependencies"
action="foo/config"
dependsOnConfig="foo/config/enabled"
/>
</menu>
</config>
Steps to reproduce
- Log in to admin panel
- Open up the top-level menu item that contains the menu items in question
Expected result
The menu items are not visible.
Actual result
The menu items are visible.
Additional information
The menu item handling was refactored to read item data from two different sources:
- from original XML definition if cache is empty
- from transformed item data when available in cache
The issue is that the initial reading from the uncached menu.xml
node fails because the array keys used in populateFromArray
do not conform to the XSD. That in turn means that various attributes are never taken over to the transformed/cached menu entry and the dependency checks always return true.
The corresponding unit test does not reveal this issue because it makes wrong/incomplete assumptions on the incoming data. So yes, the code in question is covered but not the scenario where menu item data comes in as-is from the menu.xml
file.
Another observation I made is that, although the same problem should apply to the sortOrder
attribute, sorting actual works. That is because this attribute gets evaluated in another class where the original menu.xml
contents are available.
Quick fix would probably be to align the array keys used during transformation with the attribute names in the XSD.