Add paragraph type settion to enable permission

Created on 18 May 2017, over 7 years ago
Updated 30 November 2023, 12 months ago

Problem/Motivation

The paragraph type module creates permission records for each paragraph type.
This spams the admin permission UI.

Proposed resolution

The module should create a setting per paragraph type to enable permissions on a type.
Only then, a permission record should be created.

As this module is stable, an update hook should enable the setting for all existing paragraph types.

Remaining tasks

User interface changes

API changes

Data model changes

✨ Feature request
Status

Needs review

Version

1.0

Component

Module: Type Permissions

Created by

πŸ‡¨πŸ‡­Switzerland miro_dietiker Switzerland

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update 12 months ago
    Composer require-dev failure
  • πŸ‡ΊπŸ‡ΈUnited States partdigital

    I've rerolled the patch against 8.x-1.x and fixed the automated tests.

    Changes can be found in this MR: https://git.drupalcode.org/project/paragraphs/-/merge_requests/83/diffs

    I did make one change to however. If the permission setting isn't enabled for a paragraph then that paragraph simply isn't available to use at all. That would require us to turn on the setting for every single paragraph which kind of defeats the purpose of having the setting in the first place.

    I've updated the access hooks so that Paragraphs are not restricted if the setting is disabled. This allows us to have some paragraphs that are controlled with permissions and others that aren't. On a site with 20+ paragraphs this helps a lot.

    function paragraphs_type_permissions_paragraph_access(ParagraphInterface $entity, $operation, AccountInterface $account) {
      
      // If the permission does not exist then do not restrict access.
      $enable_permission = $entity->getParagraphType()->getThirdPartySetting('paragraphs_type_permissions', 'enable_permissions', FALSE);
      if (!$enable_permission) {
        return AccessResult::neutral();
      }
    
    }
    
    function paragraphs_type_permissions_paragraph_create_access(AccountInterface $account = NULL, array $context = array(), $entity_bundle = NULL) {
    
      // If the permission does not exist then do not restrict access.
      $paragraph_type = \Drupal::entityTypeManager()->getStorage('paragraphs_type')->load($type);
      $enable_permission = $paragraph_type->getThirdPartySetting('paragraphs_type_permissions', 'enable_permissions', FALSE);
      if (!$enable_permission) {
        return AccessResult::neutral();
      }
    
    }
    
    
  • Status changed to Needs review 12 months ago
  • πŸ‡ΊπŸ‡ΈUnited States partdigital
  • Pipeline finished with Failed
    12 months ago
    Total: 1925s
    #57352
  • Pipeline finished with Failed
    21 days ago
    Total: 45s
    #327192
Production build 0.71.5 2024