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.
When I try to use this token...
[node:nid]
...I get validation errors like...
- The Canonical URL is using the following invalid tokens: [node:nid].
- The Shortlink URL is using the following invalid tokens: [node:nid].
I'm not sure if this is a metatag bug or a context module bug.
Comment | File | Size | Author |
---|---|---|---|
#47 | metatag-n1838554-47.patch | 3.92 KB | DamienMcKenna |
#30 | metatag-allow_token_types-1838554-30.patch | 3.61 KB | jcnventura |
#22 | token_errors.png | 107.57 KB | Saratt |
Comments
Comment #1
DamienMcKennaa) Are you using the latest version of Token.module?
b) Are you filling this in on a Metatag Context page, a normal Metatag settings page or an entity (e.g. node, term) edit page?
Comment #2
arnoldbird CreditAttribution: arnoldbird commentedToken 7.x-1.4
I've attached a screenshot showing the UI where this happens. It's in the Advanced fieldset at admin/config/search/metatags/context/story?destination=admin/config/search/metatags/context
Thanks
Comment #3
rickmanelius CreditAttribution: rickmanelius commentedI'm seeing the same error... is there any way to get the node tokens in scope having set/specified a node type for the context?
Comment #4
Dustin Currie CreditAttribution: Dustin Currie commentedTo replicate
Enable token 7.x-1.4, context 7.x-3.0-beta6, metatag 7.x-1.0-beta4 and metatag_context.
Create a new context.
Add a context condition "Node Type." Enable any or all content types.
Add a context reaction of "Meta Data."
Since this context is only active on nodes, we would expect that the [node:nid] token should be available for use in meta data. However, it results in the error described above.
I'm not familiar with the token module, but have traced flagging of the token as invalid to token_get_invalid_tokens_by_context().
It is unclear to me whether or not this is an issue with context, token or metatag.
Comment #5
swati.karande CreditAttribution: swati.karande commentedHi,
I feel its not an issue about any module.There are already so many tokens for node which are available through module.
In "Canonical URL" field you should not give story/[node:nid] path.Its not a correct format. Choose that specific content(Story) from Node type section which you added in conditions section.
Select "Canonical URL" field and select tokens from "Browse available tokens" you will get node id in [node:nid] format and then save your context.
I hope it will work for you.
Comment #6
DamienMcKennaClarifying this is a problem with the Context integration.
Comment #7
DamienMcKennaMarked two issues as duplicates:
Lets focus on either removing the incompatible tokens from the token browser, or fix the token processing.
Comment #8
bago CreditAttribution: bago commentedI'd like to have this fixed (by supporting node tokens when you have a node type context), but I never worked with context: have you any hint about what to do? (I'm willing to dig into the problem and try to produce a patch, but maybe you have some suggestions for me before I start doing this.)
Comment #9
DamienMcKennaComment #10
Exploratus CreditAttribution: Exploratus commented[node:*] tokens are not working for me with Context.
Comment #11
DamienMcKennaClosed a duplicate: #2036077: Can not use custom fields on meta tags II
Comment #12
Oliver Huynh CreditAttribution: Oliver Huynh commentedThis could be an issue by php apc. I fixed the issue by flushing the cache and disabling apc.
Comment #13
Oliver Huynh CreditAttribution: Oliver Huynh commentedComment #14
DamienMcKennaThat you had to disable APC makes no sense, though needing to flush its cache may have been necessary depending on its configuration.
Comment #15
Oliver Huynh CreditAttribution: Oliver Huynh commentedNo Damien. APC is right cause with my case. I flushed caches several times and nothing happened until I disabled APC in settings.php, the module and flushed caches again.
Ref settings.php:
Comment #16
DamienMcKennaOh, the module, I never use it so I forgot about it.
Is there any benefit to using APC and memcache rather than just memcache?
Does the problem persist if you disable the 'cache_class_cache' line, i.e. only use APC for the bootstrap?
Comment #17
Oliver Huynh CreditAttribution: Oliver Huynh commentedThere are some stages of caching that I need to use both in my site.
APC to run the the PHP opcode and Memcache to check if data is generated in Drupal.
The site is production so I can't take the risk to turn on apc back.
I will spend sometime to reproduce the issue in my dev.
Comment #18
DamienMcKennaLets remove the APC part for now.
Either we need to work out how to make entity tokens work in the Context system, or we need to remove those tokens from the interface when using the Metatag:Context interface.
Comment #19
drupal-n3rd CreditAttribution: drupal-n3rd commentedHi Damien,
I still don't see how I can work around this problem that node:* tokens are not accepted within Context -> Metatags. Do you guys have a suggested workaround for the time being?
(I do not fully understand Oliver's comments regarding APC. There is no APC activated on my machine)
Thanks for help,
Erik
Comment #20
mas0h CreditAttribution: mas0h commentedI'm also stuck here, any work around?
Comment #21
alexander.sibert CreditAttribution: alexander.sibert commentedI have the same issue with Metatag latest Stable, Context latest Stable and Tokens latest Dev release. I can't use Node tokens in Meta Description or in any other Metatag fields.
Comment #22
Saratt CreditAttribution: Saratt commentedHi, I am running into the same errors(attached screenshot) on node edit/add page. APC is not enabled on the server. Following are the versions of the modules that I am using. PHP Version 5.4.34
Token 7.x-1.5
Metatag 7.x-1.4
Context 7.x-3.6
Wondering if you any of you were to able to overcome this.
Thank you.
Comment #23
giupenni CreditAttribution: giupenni commentedSame error
Comment #24
dimchich CreditAttribution: dimchich as a volunteer commentedSeems that form of settings was build with ctools and context, so the form is validated element by element.
Adding token type to options in a begin of form build process makes token type available for this form.
It is need to provide token data via hook_metatag_pattern_alter() to replace token.
Comment #25
DamienMcKenna@dimchich: Thanks for the patch! I'll try to review it soon. Please don't forget to update the status to "needs review" after you upload one, it helps everyone know there's a possible fix for us to look at.
Comment #27
dimchich CreditAttribution: dimchich as a volunteer commentedSeems that I generated p0 patch
Comment #28
dimchich CreditAttribution: dimchich as a volunteer commentedComment #29
jcnventura CreditAttribution: jcnventura as a volunteer commentedWell, this added the tokens to the token tree, so that I could use them. However, the tokens aren't properly replaced afterwards.
Comment #30
jcnventura CreditAttribution: jcnventura as a volunteer commentedThanks for the 1.5 version..
This patch completes #27 by adding the node tokens also in the 'by path' edit forms, and enables the replacement of those tokens.. It uses the ugly hack of storing the current entity being viewed on a static initialized at hook_entity_prepare_view(), but my imagination was running low, on how I could get the entity at the point where it was needed (metatag_context_reaction).
Comment #32
jcnventura CreditAttribution: jcnventura as a volunteer commentedOh, the joys of using PHP < 5.4
Comment #33
jcnventura CreditAttribution: jcnventura as a volunteer commentedComment #34
jcnventura CreditAttribution: jcnventura as a volunteer commentedI'm dumb.. This obviously needs to be done in hook_node_view() or similar, in addition to the current execute call in hook_page_build().
Comment #35
Bao Truong CreditAttribution: Bao Truong commentedPlease see the comment #36 below which references the correct patch file metatag-allow_token_types-for-term-1838554-36.patch
Comment #36
Bao Truong CreditAttribution: Bao Truong commentedAwesome work jcnventura! I was actually looking to load in term tokens instead of node tokens. I rolled out a patch that is modeled after your patch but loads in term tokens instead of node tokens. I made this patch against the latest release of the metatag module which is version 1.6 at the time of this post. For those of you looking to load in term tokens instead of node tokens, feel free to use my patch.
Looks like the patch is failing, probably because I created it against the stable 1.6 branch and not the dev branch. I have resubmitted the patch under a new issue which is created against the stable 1.6 branch https://www.drupal.org/node/2516860
Comment #37
jcnventura CreditAttribution: jcnventura as a volunteer commentedComment #40
marcelovaniI started to test this but the patches didn't apply, so I re-rolled it.
Then I realised that it was a good idea to add tokens for nodes, terms and users.
I also updated the tests to include tokens.
Please review.
Comment #41
knalstaaf CreditAttribution: knalstaaf commentedTested the patch in #40 with success, using
[node:language]
and[node:nid]
with the Domain Context module. Thanks!I noticed that it's not working with the Domains Metatag module yet, so I reported it in its issue queue.
Comment #44
DamienMcKennaThis is looking pretty good and I'm willing to add it, but it needs to be rerolled.
Comment #45
marcelovaniRe-rolled the patch #40.
I didn't have time to do the tests, please review the patch and if everyone is happy we can port the tests in #40
Comment #46
marcelovaniAttaching patch
Comment #47
DamienMcKennaSome minor improvements around the comments.
Comment #48
DamienMcKennaCommitted. Thanks everyone!