You are here

public function FieldPermissionsService::getAllPermissions in Field Permissions 8

Same name and namespace in other branches
  1. 8.2 src/FieldPermissionsService.php \Drupal\field_permissions\FieldPermissionsService::getAllPermissions()

Returns permissions for all fields that are using custom permissions.

This is suitable for use as a permission callback.

Return value

array An array of all permissions for all fields that implement the custom permission type.

Overrides FieldPermissionsServiceInterface::getAllPermissions

1 call to FieldPermissionsService::getAllPermissions()
FieldPermissionsService::getPermissionsByRole in src/FieldPermissionsService.php
Get all field permissions keyed by role ID.
1 string reference to 'FieldPermissionsService::getAllPermissions'
field_permissions.permissions.yml in ./field_permissions.permissions.yml
field_permissions.permissions.yml

File

src/FieldPermissionsService.php, line 118

Class

FieldPermissionsService
The field permission service.

Namespace

Drupal\field_permissions

Code

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

  /** @var \Drupal\field\FieldStorageConfigInterface[] $fields */
  $fields = $this->entityTypeManager
    ->getStorage('field_storage_config')
    ->loadMultiple();
  foreach ($fields as $key => $field) {

    // Check if this plugin defines custom permissions.
    $permission_type = $this
      ->fieldGetPermissionType($field);
    if ($permission_type !== FieldPermissionTypeInterface::ACCESS_PUBLIC) {
      $plugin = $this->permissionTypeManager
        ->createInstance($permission_type, [], $field);
      if ($plugin instanceof CustomPermissionsInterface) {
        $permissions += $plugin
          ->getPermissions();
      }
    }
  }
  return $permissions;
}