You are here

protected function UserHasEntityFieldAccess::doEvaluate in Rules 8.3

Evaluate if the user has access to the field of an entity.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity to check access on.

string $field: The name of the field to check access on.

string $operation: The operation access should be checked for. Usually one of "view" or "edit".

\Drupal\Core\Session\AccountInterface $user: The user account to test access against.

Return value

bool TRUE if the user has access to the field on the entity, FALSE otherwise.

File

src/Plugin/Condition/UserHasEntityFieldAccess.php, line 102

Class

UserHasEntityFieldAccess
Provides a 'User has entity field access' condition.

Namespace

Drupal\rules\Plugin\Condition

Code

protected function doEvaluate(ContentEntityInterface $entity, $field, $operation, AccountInterface $user) {
  if (!$entity
    ->hasField($field)) {
    return FALSE;
  }
  $access = $this->entityTypeManager
    ->getAccessControlHandler($entity
    ->getEntityTypeId());
  if (!$access
    ->access($entity, $operation, $user)) {
    return FALSE;
  }
  $definition = $entity
    ->getFieldDefinition($field);
  $items = $entity
    ->get($field);
  return $access
    ->fieldAccess($operation, $definition, $user, $items);
}