Problem/Motivation
After deleting a custom token, it still appears when retrieving the list of available tokens. This happens because the token cache is not invalidated upon deletion, unlike when a token is created or updated. As a result, stale tokens remain accessible until the cache is manually cleared or expires, which can cause confusion and unintended behavior.
Steps to reproduce
1. Create a custom token using the custom tokens module form.
2. Verify that the token appears in the list of available tokens.
3. Delete the custom token.
4. Retrieve the list of tokens again (e.g., via `hook_token_info()`, `Token Browser` or similar methods).
5. Observe that the deleted token still appears due to the cache not being invalidated.
Proposed resolution
Invalidate or clear the token cache when a custom token is deleted, similar to the cache invalidation behavior performed when creating or updating a token. This will ensure that deleted tokens are immediately removed from any token listings and prevent stale data from persisting.
Issue fork token_custom-3531812
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 #3
iheb.attia commentedComment #4
anybody@iheb.attia I think instead of the function it should use the TokenService and
->clearCache()using dependency injection:Comment #5
grevil commented@anybody, yea I think that's better. Especially since "token_clear_cache()" is defined in the token contrib module.
But "token_clear_cache()" is also used in other places inside token custom... makes me wonder, whether this module is even compatible with tokens core. Probably not.
Comment #8
grevil commentedHm there is no "clearCache" on the token service. only "resetInfo" and I am not 100% sure it does the same thing.
Furthermore, there is no replacement defined in this CR: https://www.drupal.org/node/1973488
Since we are already using "token_clear_cache()" inside the normal "TokenCustomForm", I'd say we merge this as is. If it causes any trouble in the future, we can look further into it.
Comment #10
grevil commentedComment #12
anybodyFine with that!