Skip to content

Menu item dependencies (dependsOnModule, dependsOnConfig) are broken #9720

Closed
@mam08ixo

Description

@mam08ixo

Preconditions

  1. Magento 2.2.0-dev is installed (bdb0464 at the time of writing)
  2. 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

  1. Log in to admin panel
  2. 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:

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.

Metadata

Metadata

Assignees

Labels

Fixed in 2.2.xThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releasebug report

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions