When I try to use this token...


...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.

#27 metatag-allow_token_types-1838554-27.patch1.92 KBdimchich
PASSED: [[SimpleTest]]: [MySQL] 101 pass(es).
[ View ]
#24 metatag-allow_token_types-1838554-24.patch2.19 KBdimchich
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch metatag-allow_token_types-1838554-24.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]
#22 token_errors.png107.57 KBst455


DamienMcKenna’s picture

Status:Active» Postponed (maintainer needs more info)

a) 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?

arnoldbird’s picture

new69.19 KB

Token 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


rickmanelius’s picture

I'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?

Dustin Currie’s picture

Status:Postponed (maintainer needs more info)» Active

To 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.

swati.karande’s picture

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.

DamienMcKenna’s picture

Title:node:nid token generates validation error» node:nid token generates validation error (Context)

Clarifying this is a problem with the Context integration.

DamienMcKenna’s picture

Marked two issues as duplicates:

Lets focus on either removing the incompatible tokens from the token browser, or fix the token processing.

bago’s picture

I'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.)

DamienMcKenna’s picture

Version:7.x-1.0-beta2» 7.x-1.x-dev
Component:Code» Context
Exploratus’s picture

[node:*] tokens are not working for me with Context.

DamienMcKenna’s picture

Oliver Huynh’s picture

Component:Context» User interface
Issue summary:View changes
Issue tags:+APC

This could be an issue by php apc. I fixed the issue by flushing the cache and disabling apc.

Oliver Huynh’s picture

Component:User interface» Code
DamienMcKenna’s picture

Title:node:nid token generates validation error (Context)» node:nid token generates validation error
Component:Code» Context integration

That you had to disable APC makes no sense, though needing to flush its cache may have been necessary depending on its configuration.

Oliver Huynh’s picture

No 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:

// Varnish
$conf['cache_backends'][] = 'sites/all/modules/performance/varnish/varnish.cache.inc';
$conf['cache_class_cache_page'] = 'VarnishCache';
// Drupal 7 does not cache pages when we invoke hooks during bootstrap.
// This needs to be disabled.
$conf['page_cache_invoke_hooks'] = FALSE;
$conf['cache_backends'][] = 'sites/all/modules/performance/memcache/memcache.inc';
$conf['cache_default_class'] = 'MemCacheDrupal';
$conf['cache_class_cache_form'] = 'DrupalDatabaseCache';
$conf['memcache_servers'] = array(
  '' => 'default'
$conf['memcache_key_prefix'] = 'xxx';
// APC
/*$conf['cache_backends'][] = 'sites/all/modules/performance/apc/drupal_apc_cache.inc';
$conf['cache_class_cache'] = 'DrupalAPCCache';
$conf['cache_class_cache_bootstrap'] = 'DrupalAPCCache';
$conf['cache_prefix'] = 'inlook';
DamienMcKenna’s picture

Oh, 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?

Oliver Huynh’s picture

There 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.

DamienMcKenna’s picture

Title:node:nid token generates validation error» Either enable entity tokens in Context, or disable those tokens in Context
Issue tags:-APC

Lets 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.

drupal-n3rd’s picture

Hi 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,


mas0h’s picture

I'm also stuck here, any work around?

neofelis1985’s picture

I 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.

st455’s picture

new107.57 KB

Hi, 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.

giupenni’s picture

Same error

dimchich’s picture

new2.19 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch metatag-allow_token_types-1838554-24.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Seems 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.

DamienMcKenna’s picture

Status:Active» Needs review

@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.

Status:Needs review» Needs work

The last submitted patch, 24: metatag-allow_token_types-1838554-24.patch, failed testing.

dimchich’s picture

new1.92 KB
PASSED: [[SimpleTest]]: [MySQL] 101 pass(es).
[ View ]

Seems that I generated p0 patch

dimchich’s picture

Status:Needs work» Needs review