You are here

public function NodeViewPermissionsPermissions::permissions in Node View Permissions 8

Permission function.

Added the permissions.

1 string reference to 'NodeViewPermissionsPermissions::permissions'
node_view_permissions.permissions.yml in ./node_view_permissions.permissions.yml
node_view_permissions.permissions.yml

File

src/NodeViewPermissionsPermissions.php, line 23

Class

NodeViewPermissionsPermissions
Class definition.

Namespace

Drupal\node_view_permissions

Code

public function permissions() {
  $permissions = [];
  $nodeTypes = NodeType::loadMultiple();
  foreach ($nodeTypes as $nodeType) {

    /** @var \Drupal\node\Entity\NodeType $nodeType */
    $permission = 'view any ' . $nodeType
      ->id() . ' content';
    $permissions[$permission] = [
      'title' => $this
        ->t('<em>@type_label</em>: View any content', [
        '@type_label' => $nodeType
          ->label(),
      ]),
    ];
    $permission = 'view own ' . $nodeType
      ->id() . ' content';
    $permissions[$permission] = [
      'title' => $this
        ->t('<em>@type_label</em>: View own content', [
        '@type_label' => $nodeType
          ->label(),
      ]),
    ];
  }
  return $permissions;
}