contentacms / contenta_jsonapi

Contenta CMS, the decoupled Drupal
http://www.contentacms.org/
GNU General Public License v2.0
328 stars 104 forks source link

Contenta Enhancements dynamic menu items are generating an error when Admin Toolbar Links Access Filter module is enabled #417

Closed mriffault closed 4 months ago

mriffault commented 2 years ago

Encountered issue

When enabling Admin Toolbar Links Access Filter (an Admin toolbar submodule) we got this error: Error: Call to a member function getMenuName() on null in admin_toolbar_links_access_filter_preprocess_menu() (line 48 of modules/contrib/admin_toolbar/admin_toolbar_links_access_filter/admin_toolbar_links_access_filter.module).

Diagnostic

First I thought it came from Admin toolbar module, but can't find any related issue, except a very old one which has been closed, apparently because it is outdated...

When debugging the code at this line into admin_toolbar_links_access_filter_preprocess_menu() we can find that a key $first_link['original_link'] is missing in the menu item.

image

And it seems that this key is missing for the menu items dynamically generated by Contenta Enhancements submodule, from contenta_enhancements_toolbar_alter() :

        '#items' => [
            'content' => [
              'title' => t('Content'),
              'url' => Url::fromRoute('system.admin_content'),
              '#attributes' => ['class' => ['menu-item']]
            ],
            'add_content' => [
              'title' => t('Add Content'),
              'url' => Url::fromRoute('node.add_page'),
              '#attributes' => ['class' => ['menu-item']]
            ],
          ],

Proposed solution

The solution may be to load an existing menu item, pointing to this routes, and add it to this arrays into this original_link key?