You are here

public function EntityAccessByFieldPermissions::getRealmWithPermission in Open Social 8.6

Same name and namespace in other branches
  1. 8.9 modules/custom/entity_access_by_field/src/EntityAccessByFieldPermissions.php \Drupal\entity_access_by_field\EntityAccessByFieldPermissions::getRealmWithPermission()
  2. 8 modules/custom/entity_access_by_field/src/EntityAccessByFieldPermissions.php \Drupal\entity_access_by_field\EntityAccessByFieldPermissions::getRealmWithPermission()
  3. 8.2 modules/custom/entity_access_by_field/src/EntityAccessByFieldPermissions.php \Drupal\entity_access_by_field\EntityAccessByFieldPermissions::getRealmWithPermission()
  4. 8.3 modules/custom/entity_access_by_field/src/EntityAccessByFieldPermissions.php \Drupal\entity_access_by_field\EntityAccessByFieldPermissions::getRealmWithPermission()
  5. 8.4 modules/custom/entity_access_by_field/src/EntityAccessByFieldPermissions.php \Drupal\entity_access_by_field\EntityAccessByFieldPermissions::getRealmWithPermission()
  6. 8.5 modules/custom/entity_access_by_field/src/EntityAccessByFieldPermissions.php \Drupal\entity_access_by_field\EntityAccessByFieldPermissions::getRealmWithPermission()
  7. 8.7 modules/custom/entity_access_by_field/src/EntityAccessByFieldPermissions.php \Drupal\entity_access_by_field\EntityAccessByFieldPermissions::getRealmWithPermission()
  8. 8.8 modules/custom/entity_access_by_field/src/EntityAccessByFieldPermissions.php \Drupal\entity_access_by_field\EntityAccessByFieldPermissions::getRealmWithPermission()
  9. 10.3.x modules/custom/entity_access_by_field/src/EntityAccessByFieldPermissions.php \Drupal\entity_access_by_field\EntityAccessByFieldPermissions::getRealmWithPermission()
  10. 10.0.x modules/custom/entity_access_by_field/src/EntityAccessByFieldPermissions.php \Drupal\entity_access_by_field\EntityAccessByFieldPermissions::getRealmWithPermission()
  11. 10.1.x modules/custom/entity_access_by_field/src/EntityAccessByFieldPermissions.php \Drupal\entity_access_by_field\EntityAccessByFieldPermissions::getRealmWithPermission()
  12. 10.2.x modules/custom/entity_access_by_field/src/EntityAccessByFieldPermissions.php \Drupal\entity_access_by_field\EntityAccessByFieldPermissions::getRealmWithPermission()

Get the realms array with permissions as value.

File

modules/custom/entity_access_by_field/src/EntityAccessByFieldPermissions.php, line 92

Class

EntityAccessByFieldPermissions
EntityAccessByFieldPermissions.

Namespace

Drupal\entity_access_by_field

Code

public function getRealmWithPermission() {
  $realms = [];
  $contentTypes = $this
    ->getContentTypes();
  foreach ($contentTypes as $bundle) {
    $entity_type = 'node';
    $fields = $this
      ->getEntityAccessFields($entity_type, $bundle);

    /** @var \Drupal\field\Entity\FieldConfig $field */
    foreach ($fields as $field) {
      $field_storage = $field
        ->getFieldStorageDefinition();

      // @TODO Add support for allowed_values_function.
      $allowed_values = $field_storage
        ->getSetting('allowed_values');
      if (!empty($allowed_values)) {
        foreach ($allowed_values as $field_key => $field_label) {

          // e.g. label = node.article.field_content_visibility:public.
          $permission_label = $field
            ->id() . ':' . $field_key;
          $op = 'view';
          $permission = $op . ' ' . $permission_label . ' content';
          $bundle_id = $bundle
            ->id();
          $field_name = $field
            ->getName();
          $realm = $this
            ->getRealmForFieldValue($op, $entity_type, $bundle_id, $field_name, $field_key);
          $realms[$realm] = $permission;
        }
      }
    }
  }
  return $realms;
}