Problem

I am getting the following error when using the menu_attributes module in a drupal 8 site and an anonymous user:

Notice: Undefined index: menu_attributes in menu_attributes_get_attributes() (line 370 of /var/www/drupal8/modules/menu_attributes/menu_attributes.module).

A PHP exception is displayed in all pages, when an anonymous user visits them. When an authenticated user (admin) goes to the sites, NO error is displayed.

The error occurs when trying to access the array in linenum 370:

$options = $entity->link->first()->options[MENU_ATTRIBUTES];

Looking at the configuration and the permissions for the module, I could not find any missing permissions for the anonymous user.

This is my current system:

* Debian GNU/Linux 8.4 (jessie) (TurnkeyLinux)
* Drupal 8.1.7, 2016-07-18
* menu_attributes 8.x-0.x-dev (latest update)

Proposed resolution

To circumvent this error I patched the module as follows:

--- a/modules/menu_attributes/menu_attributes.module
+++ b/modules/menu_attributes/menu_attributes.module
@@ -358,7 +358,7 @@ function menu_attributes_get_attributes(MenuLinkInterface $menu_link) {
   $menu_link_manager = \Drupal::service('plugin.manager.menu.link');
   $definition = $menu_link_manager->getDefinition($plugin_id);
 
-  if ($definition['provider'] == 'menu_link_content') {
+  if (isset($menu_attributes[MENU_ATTRIBUTES_LINK]) && $definition['provider'] == 'menu_link_content') {
     if (strpos($plugin_id, ':') === FALSE) {
       return $attributes;
     }

Remaining tasks

* Check Patch
* Search for better solution

Comments

reixd created an issue.