You are here

public function UrlAliasPermPermissions::urlAliasPermissions in URL Alias Permissions 8

Returns an array of URL alias permissions.

Return value

array An array of permissions.

1 string reference to 'UrlAliasPermPermissions::urlAliasPermissions'
url_alias_permissions.permissions.yml in ./url_alias_permissions.permissions.yml
url_alias_permissions.permissions.yml

File

src/UrlAliasPermPermissions.php, line 74

Class

UrlAliasPermPermissions
Provides dynamic permissions for the url_alias_permissions module.

Namespace

Drupal\url_alias_permissions

Code

public function urlAliasPermissions() : array {
  $permissions = [];
  $bundle_info = $this->entityTypeBundleInfo
    ->getAllBundleInfo();

  // Create an edit url alias permissions for each enabled entity type and
  // (optionally) bundle.
  foreach ($this->entityFieldManager
    ->getFieldMapByFieldType('path') as $entity_type_id => $fields) {
    $entity_type = $this->entityTypeManager
      ->getDefinition($entity_type_id);
    if (!$entity_type instanceof EntityTypeInterface) {
      continue;
    }
    $t_args = [
      '@entity_label' => $entity_type
        ->getSingularLabel(),
    ];
    switch ($entity_type
      ->getPermissionGranularity()) {
      case 'bundle':
        foreach ($fields['path']['bundles'] as $bundle_id) {
          $t_args['%bundle_label'] = $bundle_info[$entity_type_id][$bundle_id]['label'];
          $permissions["edit {$bundle_id} {$entity_type_id} url alias"] = [
            'title' => $this
              ->t('Create and edit %bundle_label @entity_label URL alias', $t_args),
          ];
        }
        break;
      case 'entity_type':
        $permissions["edit {$entity_type_id} url alias"] = [
          'title' => $this
            ->t('Create and edit @entity_label URL alias', $t_args),
        ];
        break;
    }
  }
  return $permissions;
}