Administration menu throws an error:

Warning: strtr() expects parameter 1 to be string, array given in admin_menu_tree() (line 27 of /var/www/mysite/sites/all/modules/contrib/admin_menu/admin_menu.inc).

Please, also see #2146481: Conflict with Fieldable panels panes and Flag

How to reproduce

  1. Install Administration menu module.
  2. Create custom fieldable_panels_pane bundle via hook_entity_info_alter().
  3. Add at least one field to the custom bundle.
  4. Clear cache.

I checked out the latest development versions of Fieldable Panels Panes & Administration Menu.

Details

The problem is next menu tree item has 2 parents (@see admin_menu.inc).

Array
(
    [parent] => Array
        (
            [0] => admin/structure/fieldable-panels-panes/manage/%fieldable_panels_panes_type/fields
            [1] => admin/structure/fieldable-panels-panes/manage/%fieldable_panels_panes_type/fields
        )
    [arguments] => Array
        (
            [0] => Array
                (
                    [%fieldable_panels_panes_type] => Array
                        (
                            [0] => fieldable_panels_pane
                        )

                    [%field_ui_menu] => Array
                        (
                        )
                )
            [1] => Array
                (
                    [%fieldable_panels_panes_type] => Array
                        (
                            [0] => my_custom_bundle
                        )
                    [%field_ui_menu] => Array
                        (
                            [0] => field_image
                        )
                )
            [2] => Array
                (
                    [%fieldable_panels_panes_type] => Array
                        (
                            [0] => my_custom_bundle
                        )
                    [%field_ui_menu] => Array
                        (
                            [0] => field_image
                        )
                )
        )
)

module_invoke_all('admin_menu_map'); returns map with invalid item. I have checked fieldable_panels_panes_admin_menu_map() and seems it returns valid map array. Probably the issue is in field_ui_admin_menu_map() function, but I haven't find any problems.

I am not sure that is a fieldable_panels_panes problem, so I'll give a link to this issue from Administration menu issue queue.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

danylevskyi’s picture

Issue summary: View changes
danylevskyi’s picture

Issue summary: View changes
garyg’s picture

My home page, when using panels, will not load when the Admin menu module is enable for that user.

SocialNicheGuru’s picture

this module is returning an array of values.
Array
(
[0] => admin/structure/fieldable-panels-panes/manage/%fieldable_panels_panes_type/fields
[1] => admin/structure/fieldable-panels-panes/manage/%fieldable_panels_panes_type/fields
)

It looks like admin_menu is fetching the urls from the management menu at the time

darrenmothersele’s picture

I've got this too. Not sure how to fix?

darrenmothersele’s picture

Ok, I've got rid of the error, but I'm pretty sure this isn't the right way to solve the problem as this is not finding the cause of the issue, just patching the $expanded_map to stop the error.

I just changed

admin_menu_tree()

in admin_menu.inc so that instead of this...

  $expand_map = module_invoke_all('admin_menu_map');

I have this...

  $expand_map = module_invoke_all('admin_menu_map');
  foreach ($expand_map as $key => $item) {
    if (is_array($item['parent'])) {
      $expand_map[$key]['parent'] = reset($item['parent']);
    }
  }
Dave Reid’s picture

Status: Active » Needs review
FileSize
2.62 KB

Yes, our implementation conflicts with #2084217: Make field_ui_admin_menu_map() actually work for all entity types. Here's the switch to make it compatible again rather than re-doing the work.

Dave Reid’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

cmonnow’s picture

I receive the same error except with the flag module (using fields).

I believe darrenmothersele's hack to admin_menu.inc is the safest solution since it confines the risk to the admin_menu module functionality (but I haven't thought of any other repercussions).

As Dave Reid mentioned, this bug came out when the field_ui admin menu was generalised for all entity types. So when the new admin menu module hooks into the hook_admin_menu_map function in addition to a third-party module that creates the same key, we end up with two 'parent' clones within the same group due a flaw in module_invoke_all(), which in turn causes PHP's strtr() function to fail (expecting a string rather than an array as the first parameter).

module_invoke_all() uses PHP's array_merge_recursive() function to merge the multiple hook-returned values. This function does not merge two identical key => string values into a single pair but instead creates a single key with two cloned strings in an array i.e. 'key' => 'string', 'string'.

I believe no real progress will be made until Drupal 8 so maybe all modules including admin menu should assume that parent may contain more than one parent value and not assume strtr() is safe to apply.

Dave Reid’s picture

@cmonnow: Please see https://www.drupal.org/node/2397007 for an example of how this can be fixed in the modules that provide fieldalble entity types. So you'll want to report this as a bug in the Flag module.

cmonnow’s picture

@ Dave Reid: Thanks for the example and clarification.

For now I've posted a link to the example in the Flag issue queue (https://www.drupal.org/node/2397047).

Cheers

itarato’s picture

I admit I haven't spent the proper time to evaluate the problem, however found that the problem occurs when there are fields on the pane and in that case the admin menu module hook redifines the items. Attached a smaller patch.