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.
I've recently switched to the dev version of Flag (from version 3.2) and now I'm seeing this message everytime I clear the cache:
Notice: Undefined index: token type in flag_token_info() (line 88 of sites/all/modules/contrib/flag/flag.tokens.inc).
Comment | File | Size | Author |
---|---|---|---|
#34 | 2197041-34.patch | 606 bytes | stefan.r |
#31 | 2197041-31.patch | 605 bytes | rlmumford |
Comments
Comment #1
Pere OrgaInvestigating the issue, I think it's be a bug of xmlsitemap module, seems to not define a token type.
I'm attaching a patch that checks if there is a token type before trying to add a token. In theory not needed, but IMO these type of checks doesn't hurt.
Comment #2
Pere OrgaComment #3
joachim CreditAttribution: joachim commentedDoesn't Token module fill in the 'token type' property for all entity types?
Comment #4
Pere OrgaSorry, I don't know.
For some reason,
entity_get_info()
is returning me an entity typemenu_link
withouttoken type
defined, and because the array returned byflag_get_types()
containsmenu_link
I get a notice in some pages.Comment #5
joachim CreditAttribution: joachim commentedIt's http://drupalcode.org/project/token.git/blob/refs/heads/7.x-1.x:/token.m... but I haven't time right now to read the function and figure it out...
Comment #6
joachim CreditAttribution: joachim commentedAFAICT, the token type is filled in for any entity type that doesn't define it:
Is xmlsitemap module doing something weird to prevent this?
Comment #7
mparker17I get this error on every page request on my site, including page requests to the backend of the site (running the Seven theme, not my custom theme).
I'm running Drupal 7.26 on both Pantheon (PHP 5.3.17) and my local machine (PHP 5.4.10). I'm running
flag-7.x-3.4
(flag_actions
andflag_bookmark
are disabled),token-7.x-1.5
andxmlsitemap-7.x-2.0
.It looks like the superficial cause of the error is that
$entity_info['menu_links']['token type']
doesn't exist. It does exist for all the other things in the$entity_info
array. The$entity_info
array is retrieved in the previous line of code by calling the core functionentity_get_info()
.After a bit of debugging, it looks like the function
xmlsitemap_menu_entity_info_alter()
inxmlsitemap_menu/xmlsitemap_menu.module
adds the menu_links sub-array, but does not provide atoken type
key.Looking at the current D7 documentation for hook_entity_info() and hook_entity_info_alter(), it appears that the
token type
key is not required (in fact, it's not even mentioned in the API specification).This omission could be an oversight in the core documentation, but regardless: if it's not in the spec at the current time, then we can't expect other currently-existing contributed modules to know about it and provide it. I think @Pere Orga's patch is the correct solution to this problem.
Comment #8
mparker17I can confirm that @Pere Orga's patch meets Drupal coding standards and applying the patch fixes it on my site.
As far as I'm concerned, this patch is RTBC.
Comment #9
joachim CreditAttribution: joachim commentedThe right fix is over here: #2223911: xmlsitemap_menu.module uses hook_entity_info_alter(), and so doesn't get a token type set by token module.
It's always better to try to fix the root cause of a problem than to hack around it.
Comment #10
xbrianx CreditAttribution: xbrianx commentedI am also getting this issue after updating. This patch worked for me.
Comment #11
DamienMcKennaThe 'token type' value is provided by the Token module, it isn't part of core's token system. XMLSitemap doesn't list the Token module as a dependency, therefore it shouldn't be assumed to work with its APIs. Also, Flag doesn't list Token as a dependency, though is using an API change that only Token provides. I recommend applying this fix and updating the module's dependencies list to include Token.
Comment #12
joachim CreditAttribution: joachim commentedToken is not a dependency, it's just a module that we support if it's there.
Comment #13
DamienMcKennaOk, I missed the "if(module_exists('token'))" part, sorry for misreading the code last night.
Upon mature reflection =) I concur that the problem is not Flag's fault. That said, the patch above does solve the problem.
Comment #14
Pere OrgaHi
The patch shuts up the notice but does it solve the problem? Or should the issue be fixed in #2223911?
What I see from
grep -r "token type" *
is that all other contrib modules do check if 'token type' is set, before trying to access it.Comment #15
funtik44 CreditAttribution: funtik44 commentedI have this problem too after update to version 3.5.
Comment #16
marcoka CreditAttribution: marcoka commentedproblem confirmed here too.
Comment #17
darol100 CreditAttribution: darol100 commented1: Undefined-index-token-type-in-flag_token_info-2197041-1.patch queued for re-testing.
Comment #18
joachim CreditAttribution: joachim commentedSee comment #9.
Comment #19
Shawn DeArmond CreditAttribution: Shawn DeArmond commentedI submitted a patch to #2223911: xmlsitemap_menu.module uses hook_entity_info_alter(), and so doesn't get a token type set by token module
Please try it out and see if it works, but more importantly, if it breaks anything else.
Comment #20
brice_gato CreditAttribution: brice_gato commentedIt will be well to anticipate this case which costs nothing, because in the future it may come from another module other than XMLSitemap.
Comment #21
thedavidmeister CreditAttribution: thedavidmeister commentedI disagree that what is being suggested here is a hack.
From the PHP manual:
What we are doing here is relying on the default value of an uninitialized variable. Whether we think the variable "should" be initialized or not somewhere else, if we're not initializing it ourselves, checking that it has been initialized before trying to access it is the correct approach, as per the PHP documentation.
Comment #22
joachim CreditAttribution: joachim commented> Relying on the default value of an uninitialized variable is problematic in the case of including one file into another which uses the same variable name.
That's about global variables.
Comment #23
rooby CreditAttribution: rooby commentedI wouldn't necessarily say the solution in the patch is a hack, however I would classify it as a band-aid solution.
It is masking the real error instead of fixing the root cause, which IMO is practically always a bad idea.
Comment #24
stefan.r CreditAttribution: stefan.r commentedPatch #15 in #2223911: xmlsitemap_menu.module uses hook_entity_info_alter(), and so doesn't get a token type set by token module fixed this for me.
Comment #25
kscheirerI don't have xmlsitemap installed, so my error is
Notice: Undefined index: comment in flag_token_info() (line 72 of /path/flag/flag.tokens.inc).
This is while using Drupal Commons 7.x-3.15 which ships with Flag 7.x-2.2
The patch in #1 definitely suppresses the error. I get that it's not the best fix, but if more modules are getting this wrong some defensive programming is in order. You could add a watchdog notice about the problem instead of just skipping over it though.
Comment #26
joachim CreditAttribution: joachim commented> Notice: Undefined index: comment
That's a different error message -- please file a new bug.
Comment #27
james.williams CreditAttribution: james.williams commentedThis notice can occur for any flag type that isn't for an entity. The documentation for
hook_flag_type_info()
says that 'When a flag type is for an entity, the flag type name must match the entity type' but not that flag types have to be for entity types. If a flag type exists that is not for an entity type, then the line that is throwing this notice is making a false assumption - that there will be entity info set for the flag type.This line of reasoning suggests that either the patch in comment 1 on this issue, or the one at #2295127-3: Undefined index: token type in flag_token_info() ligne 88 in flag/flag.tokens.inc, should be entirely appropriate. Yes, it's good to fix the issue(s) at source, and whilst this thread has helped identify one in xmlsitemap (and potentially comment module, in kscheirer's situation), it's just not correct to assume that the token type or entity info must have been defined for a flag type. The only effect that applying either of the patches would have is to stop those tokens from appearing as available ... which may itself still indicate the underlying problem if the flag is for a valid entity type. This means that even without the notice, there is still indication of an underlying problem if the user expects there to be tokens available for a flag - so the patch to get rid of the notice fixes the issue (when valid to do so, as explained above) without removing all indication that there may be an underlying problem (i.e. if the flag is for an entity type).
Given that, I'm updating this ticket to RTBC again.
Comment #28
james.williams CreditAttribution: james.williams commentedI should point out that if the module maintainer disagrees, then the flag type documentation must be updated to explicitly indicate that flag types must all be for a specific entity type, which I don't believe needs to be the case - Flag provides a very useful API, and I see no reason for it to force the keys of flag types to all match entity types. Perhaps if anything, there could be a way to define what entity type a flag type is 'for' (so that tokens etc could use this) that does not have to be the key of the flag type.
Comment #29
joachim CreditAttribution: joachim commented> but not that flag types have to be for entity types
Oh well spotted!
However, the patch needs work then -- it should merely be checking that the flag type is an entity type.
Also, rather than an if block I'd rather have an inverted condition with a bail at the top of the loop.
Comment #30
PlayfulWolf CreditAttribution: PlayfulWolf commentedComment #31
rlmumfordUpdated patch that checks whether the flag type is an entity type and skips to the next iteration if not. Getting this committed would be awesome, and all the watchdog calls introduced by this error are seriously slowing our sites down.
Comment #32
stefan.r CreditAttribution: stefan.r commentedpatch looks good
Comment #33
joachim CreditAttribution: joachim commentedThanks!
I'd prefer an !isset() for clarity, but unless someone rerolls by the time I get round to committing this, it can go as it stands ;)
Comment #34
stefan.r CreditAttribution: stefan.r commentedComment #36
joachim CreditAttribution: joachim commentedCommitted.
Thanks everyone!
For those who are particularly keen to see this in a new release, there is a list of issues that are tagged as blockers for 7.x-3.7: https://www.drupal.org/project/issues/search?issue_tags=7.x-3.7%20blocker /shameless plug ;)
Comment #38
Road Kill CreditAttribution: Road Kill commentedI am not but it looks like this is still a problem
Notice: Undefined index: token type in flag_token_info() (line 93