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

Command icon 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

willids created an issue. See original summary.

aderner’s picture

I’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().

youness ka’s picture

Problem/Motivation

When trying to add a Custom Token via /admin/structure/token-custom/add, access checking fails with:

Drupal\Core\Http\Exception\CacheableAccessDeniedHttpException: 
Could not find '{token_custom_type}' request argument, therefore cannot check create access.

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:

"drupal/token_custom": {
  "#3540401: Fix add token form route: include {token_custom_type} bundle param": "3540401-token_custom-add-form-bundle-param.patch"
}
willids’s picture

Works for me, many thanks

aderner’s picture

Thank you very much, patch works for me either!

anybody’s picture

Title: unable to create tokens error » Unable to create tokens error
Version: 8.x-1.0-beta2 » 8.x-1.x-dev
Priority: Normal » Major
Status: Active » Needs work

Please create a MR instead of using patches.

grevil’s picture

Status: Needs work » Reviewed & tested by the community

Thanks for the patch! Code LGTM and works as expected.

Test failures are unrelated.

grevil’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.