function UserHasEntityFieldAccess::doEvaluate
Evaluate if the user has access to the field of an entity.
Parameters
\Drupal\Core\Session\AccountInterface $user: The user account to test access against.
\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".
Return value
bool TRUE if the user has access to the field on the entity, FALSE otherwise.
File
-
src/
Plugin/ Condition/ UserHasEntityFieldAccess.php, line 104
Class
- UserHasEntityFieldAccess
- Provides a 'User has entity field access' condition.
Namespace
Drupal\rules\Plugin\ConditionCode
protected function doEvaluate(AccountInterface $user, ContentEntityInterface $entity, $field, $operation) {
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);
}