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

CommentFileSizeAuthor
#4 3584284-1.patch361 bytesmukhtarm

Issue fork paragraphs-3584284

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

prudloff created an issue. See original summary.

matt-whelan’s picture

Confirmed on Drupal 11.3.7 / Paragraphs 1.20: the _permission requirement bypasses hook_entity_create_access().

Direct precedent in core (config entity type, no parent bundle):

  • entity.menu.add_form uses _entity_create_access: 'menu'
  • filter.format_add uses _entity_create_access: 'filter_format'

Fits as a child of #3561626's split-per-entity-type approach. No regression for default installs - EntityAccessControlHandler::createAccess still grants on the entity's admin_permission before consulting hooks.

Proposed fix:

paragraphs.type_add:
  requirements:
    _entity_create_access: 'paragraphs_type'

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.

aayushpathak’s picture

working..

mukhtarm’s picture

StatusFileSize
new361 bytes

I 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

File Change

web/modules/contrib/paragraphs/paragraphs.routing.yml
Patched: _permission_entity_create_access on the
type_add route

Test 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.

/**
 * Implements hook_entity_create_access().
 */
function paragraphs_access_test_entity_create_access(AccountInterface $account, array $context, $entity_bundle) {
  if ($context['entity_type_id'] === 'paragraphs_type') {
    return AccessResult::forbidden('Blocked by paragraphs_access_test for issue #3584284 testing.');
  }
  return AccessResult::neutral();
}

aayushpathak’s picture

Status: Active » Needs review