interface FileAccessFormatterControlHandlerInterface implements EntityAccessControlHandlerInterface (View source)

Defines an interface for file access handlers that need to run on file formatters.

\Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase, which file and image formatters extend, checks 'view' access on the referenced files before displaying them. That check would be useless and costly with Core's default access control implementation for files (\Drupal\file\FileAccessControlHandler grants access based on whether there are existing entities with granted access that reference the file). But it might be needed if a different access control handler with different logic is swapped in.

\Drupal\file\Plugin\Field\FieldFormatter\FileFormatterBase thus adjusts that behavior, and only checks access if the access control handler in use for files opts in by implementing this interface.

Methods

access(EntityInterface $entity, string $operation, AccountInterface $account = NULL, bool $return_as_object = FALSE)

Checks access to an operation on a given entity or entity translation.

createAccess(string $entity_bundle = NULL, AccountInterface $account = NULL, array $context = [], bool $return_as_object = FALSE)

Checks access to create an entity.

resetCache()

Clears all cached access checks.

$this
setModuleHandler(ModuleHandlerInterface $module_handler)

Sets the module handler for this access control handler.

fieldAccess(string $operation, FieldDefinitionInterface $field_definition, AccountInterface $account = NULL, FieldItemListInterface $items = NULL, bool $return_as_object = FALSE)

Checks access to an operation on a given entity field.

Details

bool|AccessResultInterface access(EntityInterface $entity, string $operation, AccountInterface $account = NULL, bool $return_as_object = FALSE)

Checks access to an operation on a given entity or entity translation.

Use \Drupal\Core\Entity\EntityAccessControlHandlerInterface::createAccess() to check access to create an entity.

Parameters

EntityInterface $entity

The entity for which to check access.

string $operation

The operation access should be checked for. Usually one of "view", "view label", "update" or "delete".

AccountInterface $account

(optional) The user session for which to check access, or NULL to check access for the current user. Defaults to NULL.

bool $return_as_object

(optional) Defaults to FALSE.

Return Value

bool|AccessResultInterface

The access result. Returns a boolean if $return_as_object is FALSE (this is the default) and otherwise an AccessResultInterface object. When a boolean is returned, the result of AccessInterface::isAllowed() is returned, i.e. TRUE means access is explicitly allowed, FALSE means access is either explicitly forbidden or "no opinion".

bool|AccessResultInterface createAccess(string $entity_bundle = NULL, AccountInterface $account = NULL, array $context = [], bool $return_as_object = FALSE)

Checks access to create an entity.

Parameters

string $entity_bundle

(optional) The bundle of the entity. Required if the entity supports bundles, defaults to NULL otherwise.

AccountInterface $account

(optional) The user session for which to check access, or NULL to check access for the current user. Defaults to NULL.

array $context

(optional) An array of key-value pairs to pass additional context when needed.

bool $return_as_object

(optional) Defaults to FALSE.

Return Value

bool|AccessResultInterface

The access result. Returns a boolean if $return_as_object is FALSE (this is the default) and otherwise an AccessResultInterface object. When a boolean is returned, the result of AccessInterface::isAllowed() is returned, i.e. TRUE means access is explicitly allowed, FALSE means access is either explicitly forbidden or "no opinion".

resetCache()

Clears all cached access checks.

$this setModuleHandler(ModuleHandlerInterface $module_handler)

Sets the module handler for this access control handler.

Parameters

ModuleHandlerInterface $module_handler

The module handler.

Return Value

$this

bool|AccessResultInterface fieldAccess(string $operation, FieldDefinitionInterface $field_definition, AccountInterface $account = NULL, FieldItemListInterface $items = NULL, bool $return_as_object = FALSE)

Checks access to an operation on a given entity field.

This method does not determine whether access is granted to the entity itself, only the specific field. Callers are responsible for ensuring that entity access is also respected, for example by using \Drupal\Core\Entity\EntityAccessControlHandlerInterface::access().

Parameters

string $operation

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

FieldDefinitionInterface $field_definition

The field definition.

AccountInterface $account

(optional) The user session for which to check access, or NULL to check access for the current user. Defaults to NULL.

FieldItemListInterface $items

(optional) The field values for which to check access, or NULL if access is checked for the field definition, without any specific value available. Defaults to NULL.

bool $return_as_object

(optional) Defaults to FALSE.

Return Value

bool|AccessResultInterface

The access result. Returns a boolean if $return_as_object is FALSE (this is the default) and otherwise an AccessResultInterface object. When a boolean is returned, the result of AccessInterface::isAllowed() is returned, i.e. TRUE means access is explicitly allowed, FALSE means access is either explicitly forbidden or "no opinion".

See also

EntityAccessControlHandlerInterface::access