You are here

protected function GroupPermissionHandler::completePermission in Group 2.0.x

Same name and namespace in other branches
  1. 8 src/Access/GroupPermissionHandler.php \Drupal\group\Access\GroupPermissionHandler::completePermission()

Completes a permission by adding in defaults and translating its strings.

Parameters

array $permission: The raw permission to complete.

Return value

array A permission which is guaranteed to have all the required keys set.

3 calls to GroupPermissionHandler::completePermission()
GroupPermissionHandler::buildPermissionsYaml in src/Access/GroupPermissionHandler.php
Builds all permissions provided by .group.permissions.yml files.
GroupPermissionHandler::getPermissions in src/Access/GroupPermissionHandler.php
Gets all defined group permissions.
GroupPermissionHandler::getPermissionsByGroupType in src/Access/GroupPermissionHandler.php
Gets all defined group permissions for a group type.

File

src/Access/GroupPermissionHandler.php, line 169

Class

GroupPermissionHandler
Provides the available permissions based on yml files.

Namespace

Drupal\group\Access

Code

protected function completePermission($permission) {
  $permission += [
    'title_args' => [],
    'description' => '',
    'description_args' => [],
    'restrict access' => FALSE,
    'warning' => !empty($permission['restrict access']) ? 'Warning: Give to trusted roles only; this permission has security implications.' : '',
    'warning_args' => [],
    'allowed for' => [
      'anonymous',
      'outsider',
      'member',
    ],
  ];

  // Translate the title and optionally the description and warning.
  $permission['title'] = $this
    ->t($permission['title'], $permission['title_args']);
  if (!empty($permission['description'])) {
    $permission['description'] = $this
      ->t($permission['description'], $permission['description_args']);
  }
  if (!empty($permission['warning'])) {
    $permission['warning'] = $this
      ->t($permission['warning'], $permission['warning_args']);
  }
  return $permission;
}