1

I am trying to get an array of all registered admin menu items that can be used from a bin/magento command to help choose a parent item to build a child item for. I have tried using \Magento\Backend\Model\Menu\Config->getMenu() but any of the methods on the returned model result in an empty array.

1 Answer 1

1

\Magento\Backend\Model\Menu\Config::getMenu()->toArray() should work, but it only works on adminhtml because the menu.xml config files are declared for adminhtml scope.
Maybe you can try calling this before retrieving the menu: Magento\Framework\App\State::emulateAreaCode('adminhtml'). (of course don't call it static. use and instance of Magento\Framework\App\State)

emulateAreaCode accepts 3 parameters.

  • the area code (adminhtml in your case)
  • a callback that can be a method call that retrieves your menu
  • params for the callback.

Haven't tried it so not sure if this works or is a total waste of time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.