Problem/Motivation
Steps to reproduce
When I visit URL /yoast_seo/tokens I get PHP warnings.
Warning: foreach() argument must be of type array|object, null given in /app/web/modules/contrib/yoast_seo/src/Controller/YoastSeoController.php on line 46
[]The same warning is logged every time to the logs when I write something to the body field. With every character, I get one line in the logs.
For the fix, I added not empty if to the code to fix it but then I got the next error.
This is the fix I tried to do:
if (!empty($tokens)) {
// Retrieve the tokens values.
// Use the metatag token service, which use either core or token module
// regarding if this one is installed.
foreach ($tokens as $token) {
$token_values[$token] = $metatag_token->replace($token, $data);
}
}
This is the next error I got.
Symfony\Component\HttpKernel\Exception\BadRequestHttpException: Input value "tokens" contains a non-scalar value. in Symfony\Component\HttpKernel\HttpKernel->handle() (line 83 of /app/vendor/symfony/http-kernel/HttpKernel.php).
Drupal 10.1.4
PHP 8.1.18
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | yoast_seo-get-tokens-function-is-broken-9.patch | 694 bytes | ahmad abbad |
| #4 | token-working.png | 190.07 KB | hkirsman |
| #4 | tokens-broken.png | 186.93 KB | hkirsman |
Issue fork yoast_seo-3392193
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
mikkmiggur commentedComment #3
hkirsman commentedI believe the issue is the same as here
https://www.drupal.org/project/search_api/issues/3328702
src/Controller/YoastSeoController.php
->
No more error locally.
Working:

Broken:

Comment #4
hkirsman commentedComment #7
bessonweb commented#5 work for me on Drupal 10.2.5
Comment #8
bessonweb commentedAfter update to Drupal 10.3.5, the patch seems not work.
Comment #9
ahmad abbad commentedAfter using patch #5 I'm getting this warning:
Warning: Undefined array key "data" in Drupal\yoast_seo\Controller\YoastSeoController->tokens() (line 37