Tokens are missing after cron job completes,Clearing drupal cache also not showing available list of tokens. Once i reinstall token module does the trick but if i run CRON again problem exists.

CommentFileSizeAuthor
#4 tokens.png75.89 KBkevinquillen
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

manjunathdv16 created an issue. See original summary.

mchu’s picture

Running Drupal 7.22
I did an upgrade of PHP 5.3.3 to PHP 7.0.10
Token version is 7.x-1.7.
The tokens exist until I do a clear all cache, then they are gone (admin/help/token) and "No tokens available".
Does anyone have PHP7, Drupal 7 and Token working together or is this just a bad idea?

kevinquillen’s picture

Some of my tokens also stopped working after the upgrade to PHP 7. Also running Token 7.x-1.7.

I cannot replicate it locally, since my VM is running PHP 5.6.

kevinquillen’s picture

FileSize
75.89 KB

Adding screenshot of what I see on the production site. Why is this token for date blank? This is being fed from system.tokens.inc.

1

The actual list of tokens is a lot longer:

2

PHP memory is 512M, PHP 7. I cannot replicate it locally. Cleared cache dozens of times on production. Only ONCE did I see the token list populate, however, it went away on the next cron / cache clear.

pamelalies’s picture

I was trying to track down this issue with disappearing tokens (and metatags) for a couple of months, and I finally found the solution for our sites! I thought I would post it here in case anyone else might have the same root cause - because it wasn't an easy one to track down.

This issue broke all site tokens, so it was messing up lots of things - anywhere tokens were used on the sites. It was causing blank webform submission emails to be sent (because the data is fed into the emails via tokens), and several other nasty things.

I know a lot of people mentioned that it started happening after upgrading PHP to 7. In our case the problem was caused by the Colorfield module, which has some of the "curly braces" code, which is deprecated in PHP 7.4.

I applied this patch to our installed Colorfield module, and it fixed this issue that's been plaguing us.

https://www.drupal.org/project/colorfield/issues/3163653

You wouldn't think that a module throwing a warning would break so many other things, but in this case it did. If this isn't your exact problem, you might try fixing any other curly braces deprecations in any other modules you might have installed and see if it helps you as it did us.

I'm posting this solution everywhere I see people talking about this issue (which is a lot of posts on Drupal.org!) to help as many fellow developers as possible...hope it helps!

trungonly’s picture

This may help people. Once tried many other solutions as "empty cache" with no luck, I went to debug deeper into the code. And found the hook token_info() did not list other module implementations for that hook. That is due to the internal cache inside the module_implements() function for 'token_info'. Solution is passing the $reset variable to this module_implements() function for resetting the local static cache variable.

Call this code somewhere in your module, like youmodule_init() function:
module_implements('token_info', FALSE, /*$reset = */TRUE);

Then clear the cache.
This is only a work around, because this may affect performance.

jayxdev’s picture

Used this workaround #6 and it worked...

Thank you,

Just for your info ->Using Drupal 7.94, Php 8.1, and Token 7.x-1.9