function MediaPermissions::buildPermissions

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

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

Parameters

\Drupal\media\MediaTypeInterface $type: The media type.

Return value

array An associative array of permission names and descriptions.

File

core/modules/media/src/MediaPermissions.php, line 65

Class

MediaPermissions
Provides dynamic permissions for each media type.

Namespace

Drupal\media

Code

protected function buildPermissions(MediaTypeInterface $type) {
    $type_id = $type->id();
    $type_params = [
        '%type_name' => $type->label(),
    ];
    return [
        "create {$type_id} media" => [
            'title' => $this->t('%type_name: Create new media', $type_params),
        ],
        "edit own {$type_id} media" => [
            'title' => $this->t('%type_name: Edit own media', $type_params),
        ],
        "edit any {$type_id} media" => [
            'title' => $this->t('%type_name: Edit any media', $type_params),
        ],
        "delete own {$type_id} media" => [
            'title' => $this->t('%type_name: Delete own media', $type_params),
        ],
        "delete any {$type_id} media" => [
            'title' => $this->t('%type_name: Delete any media', $type_params),
        ],
        "view any {$type_id} media revisions" => [
            'title' => $this->t('%type_name: View any media revision pages', $type_params),
        ],
        "revert any {$type_id} media revisions" => [
            'title' => $this->t('Revert %type_name: Revert media revisions', $type_params),
        ],
        "delete any {$type_id} media revisions" => [
            'title' => $this->t('Delete %type_name: Delete media revisions', $type_params),
        ],
    ];
}

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