Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
After updating the Metatag module, menu_token starts throwing this error repeatedly with every page load:
Notice: Undefined index: path in menu_token_entity_context->object_load() (line 24 of /var/www/sites/all/modules/contrib/menu_token/plugins/menu_token_entity_context.inc).
The function in question is:
function object_load($options) {
$entity_type = $options['_type'];
$entity_info = entity_get_info($entity_type);
$path_components = explode('/', $entity_info['path']);
foreach ($path_components as $position => $component) {
// If this is a menu argument, then use the current position to find
// the entity id.
if (strpos($component, '%') === 0) {
break;
}
// If the current URL deviates from the expected path, assume the
// entity is not present.
if ($component !== arg($position)) {
return FALSE;
}
}
Digging for a solution, and will report back here. If anyone else has solved this already, please let me know!
Thanks,
.
Comment | File | Size | Author |
---|---|---|---|
#29 | user-token.png | 55.39 KB | annya |
#28 | menu_token-dont-rely-on-entity-info-path-attribute-707484-28-7.patch | 1.24 KB | adrien.felipe |
#12 | 2502043_identify_entity_path_11.patch | 673 bytes | brunodbo |
Comments
Comment #1
d0t101101 CreditAttribution: d0t101101 commentedRolling back to the previous version of metatag resolved this. Uncertain if this should be reported via metatag's issue tracker as a possible conflict, or remain here for resolution!
All the best,
.
Comment #2
DevElCuy CreditAttribution: DevElCuy at Dilygent commentedPlease take a look at this.
Comment #3
DamienMcKennaDid you run the database updates after updating Metatag?
Comment #4
d0t101101 CreditAttribution: d0t101101 commentedYes I did - all completed without issue.
Comment #5
DamienMcKennaCould you please install the Devel module, then edit the function above so that it outputs the $entity_type and $entity_info if $entity_info['path'] doesn't exist? For example:
Then please upload a screenshot of what is shown? Thanks.
Comment #6
DamienMcKennaPlease also test the latest -dev release.
Comment #7
erwangel CreditAttribution: erwangel commentedThis error is still there with metatag 1.6 and latest dev (as of june 30, 2015)
There was a change in the above function between the stable version and the latest dev of menu_token module.
For the moment I just added a (!empty($entity_info['path'])) test and the error has gone without any negative consequences (for the moment)
Comment #8
DamienMcKennaOH! I just realized what this is. The 'path' attribute used to be added by Metatag for core entities but was removed in 1.5. In short the Menu Token module shouldn't rely upon that module but should instead use other methods of identifying the path for a given entity.
Comment #9
knalstaaf CreditAttribution: knalstaaf commented@erwangel: where do we exactly have to put
(!empty($entity_info['path']))
please?Edit: that seems to be line 24 of plugins/menu_token_entity_context.inc (current dev) - as mentionned above. Ok, I wasn't sure (and it's monday morning, bear with me).
Comment #10
erwangel CreditAttribution: erwangel commented@knalstaaf: that's right ; not about monday's morning as for me it's sunday evening, but about file's line :)
Comment #11
DevElCuy CreditAttribution: DevElCuy at Dilygent commentedComment #12
brunodboOn line 24 in menu_token_entity_context.inc, $entity_info contains $entity_info['default path']. The attached patch (against 7.x-1.x branch) changes 'path' to 'default path' in the explode() on that line.
I'm not sure if this is enough for what we need, but it seems to work for loading users from context.
Comment #13
brunodboComment #14
d0t101101 CreditAttribution: d0t101101 commentedWorked well for me and eliminated these notices. Thanks all!
Comment #15
Anybody#12 works for me, RTBC+1, but we need someone who knows if that is logically OK!
Comment #16
hockey2112 CreditAttribution: hockey2112 commentedI have a little time before I need to go live with the site affected by this issue. Hoping for a final solution before then... If not, then I will also give this patch a try. Thanks, Anybody, for bringing this thread to my attention.
Comment #17
jrochate CreditAttribution: jrochate commentedI got a content inside a panel, and with 7.x-1.6 I started to get the error of this post.
thanks
Comment #18
AnybodyRTBC! Please commit!
Comment #19
NancyDruDoes not resolve it for me. The failing object is a user, which has neither "path" nor "default path".
Comment #20
Lord Pachelbel CreditAttribution: Lord Pachelbel commentedIs this code sufficient to fix the problem, or will this code just mask it?
(From https://www.drupal.org/node/2502325#comment-10628980)
Comment #21
Train CreditAttribution: Train commentedI had the same issue when using Panels.
I pretty much replaced that function with the previous one and all is good.
Comment #22
mach_25 CreditAttribution: mach_25 commentedAlright i did this ugly hack and got it working for me although i don't know if this is the correct solution. I'm using menu_get_item to get the path parameter.
Comment #23
johannez CreditAttribution: johannez as a volunteer commentedI'm not sure why that function was changed to what it is now and also what the intended behaviour is (more comments please in that class).
Hence, I reverted back to the old definition like d0t101101. I'm using the user entity and there is no $entity_info['path'] defined. The default path removes the error message, but doesn't give you the entity id.
Until it gets fixed by somebody who understands that function completely, I recommend rolling back to the old version:
Comment #24
fietserwinA uri callback expects a (full) entity as parameter, so that is probably why the code from that previous version was changed: it simply doesn't work. So the solution using menu_get_item is better, but I combined it with a check on the entity_info data:
Comment #26
the69 CreditAttribution: the69 commentedHello.
I used the code fietserwin from #24
Menu on site pages works fine, but there are problems with the editing menu item in the administrative interface.
When I press "edit" on menu item with token the site gives error with the text "ERR_EMPTY_RESPONSE" and not open item edit page.
What could be the problem?
Drupal 7.41
Menu Token 7.x-1.0-beta6
Comment #27
fietserwinSorry, no idea. I ran into this problem when I was updating a site that I did not build. So far, I never used this module myself, so I can't be of any further help here.
Comment #28
adrien.felipe CreditAttribution: adrien.felipe commentedAs @fietserwin exposed, we can't use uri_callback() as no entity is available. All $option contains is the entity_type.
Maybe could it be added, but it was not so far.
I'm not sure about the menu_get_item() solution, as @the69 reports, it won't work outside the scope of the item path.
Attached patch provides a check for $entity_info['path'] first, then $entity_info['default path'], and a clean NULL exit if none was available.
Comment #29
annya CreditAttribution: annya commented@wayaslij Your patch doesn't work for "User from context" option. See screenshot with settings. If we are on /user page link doesn't shows.
Do we need other cases instead of "Show link on view/edit/delete entity page"? We have only global scope(node, user pages), and don't need another scopes. So I think @fietserwin's approach is good as for me.
Comment #30
adrien.felipe CreditAttribution: adrien.felipe commented@annya, unless $path is sent to menu_get_item(), this function will use the actual URL to extract a system path:
This might work for /user, but imagine you are using the token in an email template, or you have related users on your /user page that also need to use the token. It won't work.
A solution would be to detect where other from
$entity_info['path']
or$entity_info['default path']
the needed path could be set, or to find a way to add the entity object to$options
when it is built, so we would be able to cleanly use uri_callback().Comment #31
DevElCuy CreditAttribution: DevElCuy at Dilygent commentedPlease see #2502325: menu_token logs Undefined index: path in menu_token_entity_context->object_load() .
Comment #32
alexverb CreditAttribution: alexverb as a volunteer commented