You are here

public function GroupMenu::getPermissions in Group Menu 8

Provides a list of group permissions the plugin exposes.

If you have some group permissions that would only make sense when your plugin is installed, you may define those here. They will not be shown on the permission configuration form unless the plugin is installed.

Return value

array An array of group permissions, see GroupPermissionHandlerInterface for the structure of a group permission.

Overrides GroupContentEnablerBase::getPermissions

Deprecated

in Group 1.0, will be removed before Group 2.0. Retrieve the permission_provider handler from the plugin manager instead.

See also

GroupPermissionHandlerInterface::getPermissions()

File

src/Plugin/GroupContentEnabler/GroupMenu.php, line 53

Class

GroupMenu
Provides a content enabler for nodes.

Namespace

Drupal\groupmenu\Plugin\GroupContentEnabler

Code

public function getPermissions() {

  // Add custom permissions for managing the menus since we don't have
  // "edit own" / "edit any".
  $plugin_id = $this
    ->getPluginId();

  // Allow permissions here and in child classes to easily use the plugin name
  // and target entity type name in their titles and descriptions.
  $t_args = [
    '%plugin_name' => $this
      ->getLabel(),
    '%entity_type' => $this
      ->getEntityType()
      ->getSingularLabel(),
  ];
  $defaults = [
    'title_args' => $t_args,
    'description_args' => $t_args,
  ];

  // Use the same title prefix to keep permissions sorted properly.
  $entity_prefix = '%plugin_name - Entity:';
  $relation_prefix = '%plugin_name - Relationship:';
  $permissions["view {$plugin_id} entity"] = [
    'title' => "{$entity_prefix} View %entity_type entities",
  ] + $defaults;
  $permissions["create {$plugin_id} entity"] = [
    'title' => "{$entity_prefix} Add %entity_type entities",
    'description' => 'Allows you to create a new %entity_type entity and relate it to the group.',
  ] + $defaults;
  $permissions["update {$plugin_id} entity"] = [
    'title' => "{$entity_prefix} Edit %entity_type entities",
  ] + $defaults;
  $permissions["delete {$plugin_id} entity"] = [
    'title' => "{$entity_prefix} Delete %entity_type entities",
  ] + $defaults;
  $permissions["view {$plugin_id} content"] = [
    'title' => "{$relation_prefix} View entity relations",
  ] + $defaults;
  $permissions["create {$plugin_id} content"] = [
    'title' => "{$relation_prefix} Add entity relation",
    'description' => 'Allows you to relate an existing %entity_type entity to the group.',
  ] + $defaults;
  $permissions["update {$plugin_id} content"] = [
    'title' => "{$relation_prefix} Edit entity relations",
  ] + $defaults;
  $permissions["delete {$plugin_id} content"] = [
    'title' => "{$relation_prefix} Delete entity relations",
  ] + $defaults;
  return $permissions;
}