Problem/Motivation
The paragraphs.type_add route requires a permission explicitly.
It is a better practice to use the _entity_create_access requirement, this way access can be altered with hook_entity_create_access.
Steps to reproduce
Add this hook:
/**
* Implements hook_entity_create_access().
*/
function test_entity_create_access() {
return AccessResult::forbidden();
}
You can still create paragraph types.
Proposed resolution
Replace the _permission requirement with _entity_create_access.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 3584284-1.patch | 361 bytes | mukhtarm |
Issue fork paragraphs-3584284
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
matt-whelan commentedConfirmed on Drupal 11.3.7 / Paragraphs 1.20: the
_permissionrequirement bypasseshook_entity_create_access().Direct precedent in core (config entity type, no parent bundle):
entity.menu.add_formuses_entity_create_access: 'menu'filter.format_adduses_entity_create_access: 'filter_format'Fits as a child of #3561626's split-per-entity-type approach. No regression for default installs -
EntityAccessControlHandler::createAccessstill grants on the entity'sadmin_permissionbefore consulting hooks.Proposed fix:
Wrote a kernel test with two cases, driven by a tiny test module that toggles its hook verdict via state:
testForbiddenHookDeniesRouteAccess- pre-fix FAILS, post-fix PASSES.testNeutralHookAllowsRouteAccess- passes both, proves the admin permission path is not regressed.Happy to open an MR if you'd like? Cheers.
Comment #3
aayushpathak commentedworking..
Comment #4
mukhtarm commentedI know some are working on this issue. But here is my take.
What was fixed
The paragraphs.type_add route at /admin/structure/paragraphs_type/add was using _permission: 'administer paragraphs types' which bypasses hook_entity_create_access(). The patch replaces it with _entity_create_access: 'paragraphs_type', consistent with how Drupal core handles similar config entity routes (menus, text formats, etc.).
What changed
web/modules/contrib/paragraphs/paragraphs.routing.yml
_permission→_entity_create_accesson thetype_addrouteTest results
* With paragraphs_access_test module (implements hook_entity_create_access() returning forbidden): access is DENIED — the hook is now respected ✓
* Without the test module, user 1 (superadmin): access is ALLOWED — no regression ✓
* Route requirements dump: confirms _entity_create_access: 'paragraphs_type' is active in the running Drupal router ✓
I created a custom module (paragraphs_access_test) to test the functionality.
Comment #6
aayushpathak commented