function NodePermissions::buildPermissions

Same name in other branches
  1. 9 core/modules/node/src/NodePermissions.php \Drupal\node\NodePermissions::buildPermissions()
  2. 8.9.x core/modules/node/src/NodePermissions.php \Drupal\node\NodePermissions::buildPermissions()
  3. 11.x core/modules/node/src/NodePermissions.php \Drupal\node\NodePermissions::buildPermissions()

Returns a list of node permissions for a given node type.

Parameters

\Drupal\node\Entity\NodeType $type: The node type.

Return value

array An associative array of permission names and descriptions.

File

core/modules/node/src/NodePermissions.php, line 36

Class

NodePermissions
Provides dynamic permissions for nodes of different types.

Namespace

Drupal\node

Code

protected function buildPermissions(NodeType $type) {
    $type_id = $type->id();
    $type_params = [
        '%type_name' => $type->label(),
    ];
    return [
        "create {$type_id} content" => [
            'title' => $this->t('%type_name: Create new content', $type_params),
        ],
        "edit own {$type_id} content" => [
            'title' => $this->t('%type_name: Edit own content', $type_params),
            'description' => $this->t('Note that anonymous users with this permission are able to edit any content created by any anonymous user.'),
        ],
        "edit any {$type_id} content" => [
            'title' => $this->t('%type_name: Edit any content', $type_params),
        ],
        "delete own {$type_id} content" => [
            'title' => $this->t('%type_name: Delete own content', $type_params),
            'description' => $this->t('Note that anonymous users with this permission are able to delete any content created by any anonymous user.'),
        ],
        "delete any {$type_id} content" => [
            'title' => $this->t('%type_name: Delete any content', $type_params),
        ],
        "view {$type_id} revisions" => [
            'title' => $this->t('%type_name: View revisions', $type_params),
            'description' => t('To view a revision, you also need permission to view the content item.'),
        ],
        "revert {$type_id} revisions" => [
            'title' => $this->t('%type_name: Revert revisions', $type_params),
            'description' => t('To revert a revision, you also need permission to edit the content item.'),
        ],
        "delete {$type_id} revisions" => [
            'title' => $this->t('%type_name: Delete revisions', $type_params),
            'description' => $this->t('To delete a revision, you also need permission to delete the content item.'),
        ],
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.