You are here

public function CustomPermissions::permissions in Custom Permissions 8.2

Same name and namespace in other branches
  1. 8 src/CustomPermissions.php \Drupal\config_perms\CustomPermissions::permissions()

Returns an array of filter permissions.

Return value

array Return a table of permissions

1 string reference to 'CustomPermissions::permissions'
config_perms.permissions.yml in ./config_perms.permissions.yml
config_perms.permissions.yml

File

src/CustomPermissions.php, line 47

Class

CustomPermissions
Provides dynamic permissions of the filter module.

Namespace

Drupal\config_perms

Code

public function permissions() {
  $permissions = [];

  // Generate permissions for each text format. Warn the administrator that
  // any of them are potentially unsafe.

  /** @var \Drupal\filter\FilterFormatInterface[] $formats */
  $custom_perms = $this->entityTypeManager
    ->getStorage('custom_perms_entity')
    ->loadByProperties([
    'status' => TRUE,
  ]);
  uasort($custom_perms, 'Drupal\\Core\\Config\\Entity\\ConfigEntityBase::sort');
  foreach ($custom_perms as $custom_perm) {
    if ($permission = $custom_perm
      ->label()) {
      $permissions[$permission] = [
        'title' => $permission,
        'description' => [
          '#prefix' => '<em>',
          '#markup' => $this
            ->t('Warning: This permission may have security implications.'),
          '#suffix' => '</em>',
        ],
      ];
    }
  }
  return $permissions;
}