Add node view permissions to the node bundle's permissions tab

Created on 30 December 2022, almost 2 years ago
Updated 7 February 2024, 9 months ago

Problem/Motivation

As of Drupal 9.3 each node bundle has it's own permissions tab, e.g. /admin/structure/types/manage/basic_page/permissions
The Node View Permissions permissions are missing there and it would be really convenient to see them there.

Steps to reproduce

- Install node_view_permissions module
- Create a node bundle named "basic_page"
- Navigate to /admin/structure/types/manage/basic_page/permissions

Proposed resolution

I would prefer the Node View Permissions to be added to the permissions tab itself. However, I've looked into the core implementation and I don't see an obvious way to achieve that.
So maybe a more reasonable solution would be to add a seperate tab for "View permissions" right next to the "Permissions" tab.

Remaining tasks

- Build View Permissions form to handle the permissions for a single node bundle
- Display the form on a "View permissions" tab next to the "Permissions" tab

User interface changes

A new tab "View permissions" with a seperate form to handle the permissions.

API changes

Data model changes

Feature request
Status

Needs review

Version

1.0

Component

User interface

Created by

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.

  • 🇩🇪Germany Anybody Porta Westfalica
  • 🇩🇪Germany guido_s Cologne

    I think the publication_date module solved this in a good way using permission callbacks in its permissions.yml and then extending the NodePermissions class.

    permission_callbacks:
      - \Drupal\publication_date\PublicationDateNodePermissions::nodeTypePermissions
    use Drupal\node\Entity\NodeType;
    use Drupal\node\NodePermissions;
    
    /**
     * Permissions to "Published On" field.
     */
    class PublicationDateNodePermissions extends NodePermissions {
    
      /**
       * Returns an array of node type permissions.
       *
       * @return array
       *   The node type permissions.
       *   @see \Drupal\user\PermissionHandlerInterface::getPermissions()
       */
      protected function buildPermissions(NodeType $type): array {
        $type_id = $type->id();
        $type_params = ['%type_name' => $type->label()];
    
        return [
          "set $type_id published on date" => [
            'title' => $this->t('Modify %type_name "Published On" date.', $type_params),
            'description' => $this->t('Change the "Published On" date for this content type.'),
          ],
        ];
      }
    
    }
    

    Something like this could be used here too.

  • Merge request !33330335 implemented bundle permissions → (Open) created by guido_s
  • Status changed to Needs review 9 months ago
  • 🇩🇪Germany guido_s Cologne

    I added it like that and opened a merge request.
    Please test if everything works as expected.

  • 🇩🇪Germany guido_s Cologne

    We need to check if the core version requirements in the info file need to be changed for this. I currently don't know if the NodePermissions class existed in Drupal 8 and only the bundle permissions trait was added later or something like that.

Production build 0.71.5 2024