Generated with the help of an LLM.

I used Claude to help write this summary, the code and the tests. I reviewed and tested everything myself.

Problem/Motivation

Child of #3561626. The content type add route (node.type_add, /admin/structure/types/add) and the role add route (user.role_add,
/admin/people/roles/add) only check a permission, so hook_entity_create_access() and hook_ENTITY_TYPE_create_access() are never called for
them. A module that forbids creating node_type or user_role entities can't block these add forms. Restricting who can create content types was the case
that started #3561626.

The role route was first reported in #3644297, which was combined into this issue.

Proposed resolution

Use _entity_create_access instead of _permission on both routes, like the menu, text format and language add routes already do. The admin permissions
of node_type (administer content types) and user_role (administer permissions) are the same permissions the routes check today,
so nothing changes for sites that don't implement the hook.

Remaining tasks

Review the MR.

Issue fork drupal-3643704

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

deruina created an issue. See original summary.

deruina’s picture

Status: Active » Needs review
needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new1.45 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

deruina’s picture

Status: Needs work » Needs review

Rebased on main and added #[ShareEnvironment(FALSE)] to the new kernel test, which core requires since #3623409. PHPStan and the test pass locally.

smustgrave’s picture

Status: Needs review » Needs work

For this one I don't think we need a whole new test file why not NodeAccessTest? This is where AI tests are annoying because they just make a new file and never look to extend an existing file or even an existing test.

deruina’s picture

Status: Needs work » Needs review

Thanks @smustgrave, fair point. Moved the test into the existing NodeAccessTest as testNodeTypeAddRouteAccess() and deleted the new file. It still
fails without the routing change.

smustgrave’s picture

Insread of opening more tickets should we combine #3644297: Add role route ignores hook_entity_create_access() ?

deruina’s picture

Issue summary: View changes
deruina’s picture

Title: Add content type route ignores hook_entity_create_access() » Add content type and add role routes ignore hook_entity_create_access()
deruina’s picture

Thanks @smustgrave, done: the add role route change and its test from #3644297 are now in this MR, and I'll close that issue as a duplicate.

There are three more add routes with the same problem: comment type, date format, and view/form modes. Should I add them here too, instead of opening new issues? (cc @prudloff,
who suggested child issues in #3561626)