class UserHasEntityFieldAccess
Provides a 'User has entity field access' condition.
@todo Add access callback information from Drupal 7.
Plugin annotation
@Condition(
id = "rules_entity_field_access",
label = @Translation("User has entity field access"),
category = @Translation("User"),
context_definitions = {
"user" = @ContextDefinition("entity:user",
label = @Translation("User"),
description = @Translation("Specifies the user account for which to check access. If left empty, the currently logged in user will be used."),
assignment_restriction = "selector",
required = FALSE
),
"entity" = @ContextDefinition("entity",
label = @Translation("Entity"),
description = @Translation("Specifies the entity for which to evaluate the condition."),
assignment_restriction = "selector"
),
"field" = @ContextDefinition("string",
label = @Translation("Field"),
description = @Translation("The name of the field to check for."),
assignment_restriction = "input",
options_provider = "\Drupal\rules\TypedData\Options\FieldListOptions"
),
"operation" = @ContextDefinition("string",
label = @Translation("Access operation"),
description = @Translation("The access type to check."),
assignment_restriction = "input",
default_value = "view",
required = FALSE,
options_provider = "\Drupal\rules\TypedData\Options\ViewEditOptions"
),
}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
- class \Drupal\Core\Executable\ExecutablePluginBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\Core\Executable\ExecutableInterface, \Drupal\Core\Cache\CacheableDependencyInterface, \Drupal\Core\Plugin\ContextAwarePluginInterface uses \Drupal\Core\Plugin\ContextAwarePluginTrait
- class \Drupal\Core\Condition\ConditionPluginBase extends \Drupal\Core\Executable\ExecutablePluginBase implements \Drupal\Core\Condition\ConditionInterface uses \Drupal\Core\Plugin\ContextAwarePluginAssignmentTrait
- class \Drupal\rules\Core\RulesConditionBase extends \Drupal\Core\Condition\ConditionPluginBase implements \Drupal\rules\Core\RulesConditionInterface uses \Drupal\rules\Context\ContextProviderTrait, \Drupal\rules\Core\ExecutablePluginTrait, \Drupal\rules\Core\ConfigurationAccessControlTrait
- class \Drupal\rules\Plugin\Condition\UserHasEntityFieldAccess extends \Drupal\rules\Core\RulesConditionBase implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface
- class \Drupal\rules\Core\RulesConditionBase extends \Drupal\Core\Condition\ConditionPluginBase implements \Drupal\rules\Core\RulesConditionInterface uses \Drupal\rules\Context\ContextProviderTrait, \Drupal\rules\Core\ExecutablePluginTrait, \Drupal\rules\Core\ConfigurationAccessControlTrait
- class \Drupal\Core\Condition\ConditionPluginBase extends \Drupal\Core\Executable\ExecutablePluginBase implements \Drupal\Core\Condition\ConditionInterface uses \Drupal\Core\Plugin\ContextAwarePluginAssignmentTrait
- class \Drupal\Core\Executable\ExecutablePluginBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\Core\Executable\ExecutableInterface, \Drupal\Core\Cache\CacheableDependencyInterface, \Drupal\Core\Plugin\ContextAwarePluginInterface uses \Drupal\Core\Plugin\ContextAwarePluginTrait
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
Expanded class hierarchy of UserHasEntityFieldAccess
File
-
src/
Plugin/ Condition/ UserHasEntityFieldAccess.php, line 50
Namespace
Drupal\rules\Plugin\ConditionView source
class UserHasEntityFieldAccess extends RulesConditionBase implements ContainerFactoryPluginInterface {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a UserHasEntityFieldAccess object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin ID for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity_type.manager service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container->get('entity_type.manager'));
}
/**
* Evaluate if the user has access to the field of an entity.
*
* @param \Drupal\Core\Session\AccountInterface $user
* The user account to test access against.
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
* The entity to check access on.
* @param string $field
* The name of the field to check access on.
* @param string $operation
* The operation access should be checked for. Usually one of "view" or
* "edit".
*
* @return bool
* TRUE if the user has access to the field on the entity, FALSE otherwise.
*/
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);
}
}