I am trying to create a custom token and getting this error
Path: /admin/structure/token-custom/add. Drupal\Core\Http\Exception\CacheableAccessDeniedHttpException: Could not find '{token_custom_type}' request argument, therefore cannot check create access. in Drupal\Core\Routing\AccessAwareRouter->checkAccess() (line 114 of /home/DOMAINNAME/public_html/core/lib/Drupal/Core/Routing/AccessAwareRouter.php).
When I click the add token button it loads up a homepage in the admin panel, I have removed all redirect from .htaccess, redirect 404 and redirect tables in the Database have been emptied.
Permissions are set correctly for administrator
Drupal 11.2.3
PHP 8.4
Custom Tokens 8.x-1.0-beta2
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 3540401-token_custom-add-form-bundle-param.patch | 1.06 KB | youness ka |
Issue fork token_custom-3540401
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
aderner commentedI’m experiencing the same issue, and it appears to occur in Drupal 11.
After a quick check, it seems the problem is related to the $type parameter in the token_custom_tokens() function within the token_custom.module file. Probably because of some issues in function token_custom_type_allowlist().
Comment #3
youness ka commentedProblem/Motivation
When trying to add a Custom Token via /admin/structure/token-custom/add, access checking fails with:
This occurs even when at least one Custom Token Type exists and permissions are correctly granted.
Environment
• Drupal core: 11.2.3
• PHP: 8.4
• Module: token_custom 8.x-1.0-beta2
Steps to reproduce
1. Ensure a Custom Token Type exists (e.g. machine name custom).
2. Visit /admin/structure/token-custom/add.
3. Observe redirect to the site’s 403 page (often the front page) and/or the exception above in logs.
Root cause
The entity link template for the add form does not include the required bundle parameter.
TokenCustom’s @ContentEntityType annotation currently defines:
"add-form" = "/admin/structure/token-custom/add"The add form route requires the bundle argument {token_custom_type}. In addition, there is no explicit "add" form handler defined, which can further confuse the creation flow.
Proposed resolution
• Update the add-form entity link template to include the bundle parameter:
"add-form" = "/admin/structure/token-custom/add/{token_custom_type}"• Add an explicit "add" form handler pointing to Drupal\token_custom\Form\TokenCustomForm.
How I tested
1. Applied the patch.
2. Cleared caches (drush cr).
3. Verified both flows work:
• /admin/structure/token-custom/add now lists available token types.
• /admin/structure/token-custom/add/custom opens the creation form directly (replace custom with the actual machine name if different).
4. Created a token successfully; no more access errors or redirects.
Impact/Risk
• Low risk. Changes are limited to entity link templates and form handlers.
• Aligns with core patterns (e.g., Node entity uses {node_type} in its add-form link).
• No data model changes; no updates required.
Composer patch label suggestion
If helpful for others consuming via Composer:
Comment #4
willids commentedWorks for me, many thanks
Comment #5
aderner commentedThank you very much, patch works for me either!
Comment #6
anybodyPlease create a MR instead of using patches.
Comment #8
grevil commentedThanks for the patch! Code LGTM and works as expected.
Test failures are unrelated.
Comment #10
grevil commented