class ShortcutSetAccessControlHandler extends EntityAccessControlHandler (View source)

Defines the access control handler for the shortcut set entity type.

Traits

Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.

Provides dependency injection friendly methods for serialization.

Properties

protected TranslationInterface $stringTranslation

The string translation service.

from  StringTranslationTrait
protected array $_serviceIds

An array of service IDs keyed by property name used for serialization.

from  DependencySerializationTrait
protected array $_entityStorages

An array of entity type IDs keyed by the property name of their storages.

from  DependencySerializationTrait
protected ModuleHandlerInterface $moduleHandler

The module handler to invoke hooks on.

from  EntityHandlerBase
protected array $accessCache

Stores calculated access check results.

from  EntityAccessControlHandler
protected string $entityTypeId

The entity type ID of the access control handler instance.

from  EntityAccessControlHandler
protected EntityTypeInterface $entityType

Information about the entity type.

from  EntityAccessControlHandler
protected bool $viewLabelOperation

Allows to grant access to just the labels.

from  EntityAccessControlHandler

Methods

t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

getStringTranslation()

Gets the string translation service.

$this
setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

moduleHandler()

Gets the module handler.

$this
setModuleHandler(ModuleHandlerInterface $module_handler)

Sets the module handler for this handler.

__construct(EntityTypeInterface $entity_type)

Constructs an access control handler instance.

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.

processAccessHookResults(array $access)

We grant access to the entity if both of these conditions are met:

  • No modules say to deny access.

checkAccess(EntityInterface $entity, string $operation, AccountInterface $account)

Performs access checks.

getCache(string $cid, string $operation, string $langcode, AccountInterface $account)

Tries to retrieve a previously cached access value from the static cache.

setCache(AccessResultInterface $access, string $cid, string $operation, string $langcode, AccountInterface $account)

Statically caches whether the given user has access.

resetCache()

Clears all cached access checks.

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

Checks access to create an entity.

checkCreateAccess(AccountInterface $account, array $context, string|null $entity_bundle = NULL)

Performs create access checks.

prepareUser(AccountInterface $account = NULL)

Loads the current account object, if it does not exist yet.

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.

checkFieldAccess(string $operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL)

Default field access as determined by this access control handler.

Details

protected TranslatableMarkup t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.

In order for strings to be localized, make them available in one of the ways supported by the

Parameters

string $string

A string containing the English text to translate.

array $args

(optional) An associative array of replacements to make after translation. Based on the first character of the key, the value is escaped and/or themed. See \Drupal\Component\Render\FormattableMarkup::placeholderFormat() for details.

array $options

(optional) An associative array of additional options, with the following elements:

  • 'langcode' (defaults to the current language): A language code, to translate to a language other than what is used to display the page.
  • 'context' (defaults to the empty context): The context the source string belongs to. See the @link i18n Internationalization topic @endlink for more information about string contexts.

Return Value

TranslatableMarkup

An object that, when cast to a string, returns the translated string.

See also

FormattableMarkup::placeholderFormat
TranslatableMarkup::__construct

protected formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

Parameters

$count
$singular
$plural
array $args
array $options

See also

TranslationInterface::formatPlural

protected getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

Parameters

$langcode

See also

PluralFormulaInterface::getNumberOfPlurals

protected TranslationInterface getStringTranslation()

Gets the string translation service.

Return Value

TranslationInterface

The string translation service.

$this setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

Parameters

TranslationInterface $translation

The string translation service.

Return Value

$this

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

protected ModuleHandlerInterface moduleHandler()

Gets the module handler.

Return Value

ModuleHandlerInterface

The module handler.

$this setModuleHandler(ModuleHandlerInterface $module_handler)

Sets the module handler for this handler.

Parameters

ModuleHandlerInterface $module_handler

The module handler.

Return Value

$this

__construct(EntityTypeInterface $entity_type)

Constructs an access control handler instance.

Parameters

EntityTypeInterface $entity_type

The entity type definition.

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".

protected AccessResultInterface processAccessHookResults(array $access)

We grant access to the entity if both of these conditions are met:

  • No modules say to deny access.

  • At least one module says to grant access.

Parameters

array $access

An array of access results of the fired access hook.

Return Value

AccessResultInterface

The combined result of the various access checks' results. All their cacheability metadata is merged as well.

See also

AccessResultInterface::orIf

protected AccessResultInterface checkAccess(EntityInterface $entity, string $operation, AccountInterface $account)

Performs access checks.

This method is supposed to be overwritten by extending classes that do their own custom access checking.

Parameters

EntityInterface $entity

The entity for which to check access.

string $operation

The entity operation. Usually one of 'view', 'view label', 'update' or 'delete'.

AccountInterface $account

The user for which to check access.

Return Value

AccessResultInterface

The access result.

protected AccessResultInterface|null getCache(string $cid, string $operation, string $langcode, AccountInterface $account)

Tries to retrieve a previously cached access value from the static cache.

Parameters

string $cid

Unique string identifier for the entity/operation, for example the entity UUID or a custom string.

string $operation

The entity operation. Usually one of 'view', 'update', 'create' or 'delete'.

string $langcode

The language code for which to check access.

AccountInterface $account

The user for which to check access.

Return Value

AccessResultInterface|null

The cached AccessResult, or NULL if there is no record for the given user, operation, langcode and entity in the cache.

protected AccessResultInterface setCache(AccessResultInterface $access, string $cid, string $operation, string $langcode, AccountInterface $account)

Statically caches whether the given user has access.

Parameters

AccessResultInterface $access

The access result.

string $cid

Unique string identifier for the entity/operation, for example the entity UUID or a custom string.

string $operation

The entity operation. Usually one of 'view', 'update', 'create' or 'delete'.

string $langcode

The language code for which to check access.

AccountInterface $account

The user for which to check access.

Return Value

AccessResultInterface

Whether the user has access, plus cacheability metadata.

resetCache()

Clears all cached access checks.

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".

protected AccessResultInterface checkCreateAccess(AccountInterface $account, array $context, string|null $entity_bundle = NULL)

Performs create access checks.

This method is supposed to be overwritten by extending classes that do their own custom access checking.

Parameters

AccountInterface $account

The user for which to check access.

array $context

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

string|null $entity_bundle

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

Return Value

AccessResultInterface

The access result.

protected AccountInterface prepareUser(AccountInterface $account = NULL)

Loads the current account object, if it does not exist yet.

Parameters

AccountInterface $account

The account interface instance.

Return Value

AccountInterface

Returns the current account object.

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".

protected AccessResultInterface checkFieldAccess(string $operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL)

Default field access as determined by this access control handler.

Parameters

string $operation

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

FieldDefinitionInterface $field_definition

The field definition.

AccountInterface $account

The user session for which to check access.

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.

Return Value

AccessResultInterface

The access result.