Support from Acquia helps fund testing for Drupal Acquia logo

Comments

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

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

Thanks

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

Hi,
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;
//memcache
$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(
  '127.0.0.1:11211' => '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,

Erik

mas0h’s picture

I'm also stuck here, any work around?

alexander.sibert’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.

Saratt’s picture

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

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

Seems that I generated p0 patch

dimchich’s picture

Status: Needs work » Needs review
jcnventura’s picture

Status: Needs review » Needs work

Well, this added the tokens to the token tree, so that I could use them. However, the tokens aren't properly replaced afterwards.

jcnventura’s picture

Status: Needs work » Needs review
FileSize
3.61 KB

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

Status: Needs review » Needs work

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

jcnventura’s picture

Oh, the joys of using PHP < 5.4

jcnventura’s picture

Status: Needs work » Needs review
jcnventura’s picture

Status: Needs review » Needs work

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

Bao Truong’s picture

Please see the comment #36 below which references the correct patch file metatag-allow_token_types-for-term-1838554-36.patch

Bao Truong’s picture

Awesome 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

jcnventura’s picture

Status: Needs work » Needs review

The last submitted patch, 35: metatag-allow_token_types-for-term-1838554-33.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 36: metatag-allow_token_types-for-term-1838554-36.patch, failed testing.

marcelovani’s picture

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

knalstaaf’s picture

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

Status: Needs review » Needs work

The last submitted patch, 40: metatag_context_tokens_1838554-40.patch, failed testing.

The last submitted patch, 40: metatag_context_tokens_1838554-40.patch, failed testing.

DamienMcKenna’s picture

This is looking pretty good and I'm willing to add it, but it needs to be rerolled.

marcelovani’s picture

Status: Needs work » Needs review

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

marcelovani’s picture

DamienMcKenna’s picture

Status: Needs review » Fixed

Committed. Thanks everyone!

  • DamienMcKenna committed 0da0de9 on 7.x-1.x
    Issue #1838554 by dimchich, jcnventura, Bao Truong, marcelovani,...

Status: Fixed » Closed (fixed)

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