You are here

public static function ProtectionRule::postLoad in User protect 8

Acts on loaded entities.

Parameters

\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage object.

\Drupal\Core\Entity\EntityInterface[] $entities: An array of entities.

Overrides EntityBase::postLoad

File

src/Entity/ProtectionRule.php, line 284

Class

ProtectionRule
Defines the Protection rule entity.

Namespace

Drupal\userprotect\Entity

Code

public static function postLoad(EntityStorageInterface $storage_controller, array &$entities) {
  parent::postLoad($storage_controller, $entities);
  foreach ($entities as $entity) {
    $permission = $entity
      ->getPermissionName();
    if ($permission) {
      $roles = array_keys(user_role_names(FALSE, $permission));
      $entity
        ->setBypassRoles($roles);
    }
  }
}