Loading
task: #3627991 Replace drupal_static() in token.module, deprecated in Drupal 11.5
Closes #3627991.
- The menu link and term parent loaders move to two services,
TokenMenuLinkHelperandTokenTermHelper, registered under their class name only. They keep the titles in their own properties for the request, so they need neitherdrupal_static()nor a memory cache bin (cache.memoryonly exists from Drupal 11.3), and run the same code from Drupal 10.3 to 12.token_menu_link_translated_title()moves toTokenMenuLinkHelper::getTranslatedTitle(). - The helper methods take typed arguments (
int $tid,string $langcode…), so theis_numeric()check on the term ID goes away. TokenEntityHooksandTokenTokensHooksget the helpers through service closures, so the hook classes stay cheap to build for the many hooks that never use them.token_menu_link_load_all_parents(),token_taxonomy_term_load_all_parents()andtoken_menu_link_translated_title()become deprecated wrappers around the helpers. They cast their arguments, and the term one still returns no parents for a non-numeric term ID.token_clear_cache()is deprecated. Saving a date format or a field only changes which tokens exist, so the hooks, the token cache controller and the Drush cache clear now callToken::resetInfo()directly. The entity type mappings come from the entity type definitions and the parent titles only live for the request, so nothing that called it needed those reset. It also no longer resetstoken_book_link_load, which no function uses.token_book_load_all_parents()is not converted, only deprecated: book tokens are only defined while the Book module does not provide its own (#3588324). Its two calls inTokenTokensHookscarry an inline PHPStan ignore with that reason.- A new
taxonomy_term_presavehook clears the term parents, like the existingmenu_link_content_presaveone does for menu links.TaxonomyTest::testParentsTokenFollowsParentRenameInSameRequest()covers it: it fails on 8.x-1.x ([term:parents]still returns the old name after the parent is renamed) and passes with the change.
The phpunit (next major) failures come from Drupal 12 core changes outside this MR and belong in a separate issue.
Checked locally on Drupal 11.4: all kernel tests pass, and TaxonomyTest fails again when the term reset in TokenEntityHooks::taxonomyTermPresave() is removed; the hooks, the cache controller and the Drush callable each invalidate the token_info cache tag (checked with a throwaway kernel test, which fails when the hook's reset is removed); phpcs and PHPStan report nothing new.
AI-Generated: Yes (Claude Code was used to write the code and the test in this merge request and to draft this description. I reviewed the change before posting it.)
Edited by Frank Mably