class ShortcutSetStorage extends ConfigEntityStorage implements ShortcutSetStorageInterface (View source)

Defines a storage for shortcut_set entities.

Traits

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

Provides dependency injection friendly methods for serialization.

Constants

MAX_ID_LENGTH

Length limit of the configuration entity ID.

Most file systems limit a file name's length to 255 characters, so ConfigBase::MAX_NAME_LENGTH restricts the full configuration object name to 250 characters (leaving 5 for the file extension). The config prefix is limited by ConfigEntityType::PREFIX_LENGTH to 83 characters, so this leaves 166 remaining characters for the configuration entity ID, with 1 additional character needed for the joining dot.

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.

protected string $entityTypeId

Entity type ID for this storage.

from  EntityStorageBase
protected EntityTypeInterface $entityType

Information about the entity type.

from  EntityStorageBase
protected string $idKey

Name of the entity's ID field in the entity database table.

from  EntityStorageBase
protected $uuidKey {@inheritdoc} from  ConfigEntityStorage
protected string $langcodeKey

The name of the entity langcode property.

from  EntityStorageBase
protected UuidInterface $uuidService

The UUID service.

from  EntityStorageBase
protected MemoryCacheInterface $memoryCache

The memory cache.

from  EntityStorageBase
protected string $memoryCacheTag

The memory cache cache tag.

from  EntityStorageBase
protected ConfigFactoryInterface $configFactory

The config factory service.

from  ConfigEntityStorage
protected StorageInterface $configStorage

The config storage service.

from  ConfigEntityStorage
protected LanguageManagerInterface $languageManager

The language manager.

from  ConfigEntityStorage
protected bool $overrideFree

Determines if the underlying configuration is retrieved override free.

from  ConfigEntityStorage
protected Connection $connection

The database connection.

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_info, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager, MemoryCacheInterface $memory_cache, Connection $connection)

Constructs a ShortcutSetStorageController object.

string
getEntityClass(string|null $bundle = NULL)

Retrieves the class name used to create the entity.

__get(string $name)

Warns subclasses not to directly access the deprecated entityClass property.

void
__set(string $name, mixed $value)

Warns subclasses not to directly set the deprecated entityClass property.

string
getEntityTypeId()

Gets the entity type ID.

getEntityType()

Gets the entity type definition.

string
buildCacheId(int $id)

Builds the cache ID for the passed in entity ID.

loadUnchanged(mixed $id)

Loads an unchanged entity from the database.

resetCache(array $ids = NULL)

Resets the internal entity cache.

getFromStaticCache(array $ids)

Gets entities from the static cache.

setStaticCache(array $entities)

Stores entities in the static entity cache.

invokeHook(string $hook, EntityInterface $entity)

Invokes a hook on behalf of the entity.

create(array $values = [])

Constructs a new entity object, without permanently saving it.

doCreate(array $values)

Performs storage-specific creation of entities.

load(mixed $id)

Loads one entity.

loadMultiple(array $ids = NULL)

Loads one or more entities.

doLoadMultiple(array $ids = NULL)

Performs storage-specific loading of entities.

preLoad(array $ids = NULL)

Gathers entities from a 'preload' step.

postLoad(array $entities)

Attaches data to entities upon loading.

mapFromStorageRecords(array $records)

Maps from storage records to entity objects.

bool
has(int|string $id, EntityInterface $entity)

Determines if this entity already exists in storage.

delete(array $entities)

Deletes permanently saved entities.

doDelete(EntityInterface[] $entities)

Performs storage-specific entity deletion.

SAVED_NEW
save(EntityInterface $entity)

Implements Drupal\Core\Entity\EntityStorageInterface::save().

int|string
doPreSave(EntityInterface $entity)

Performs presave entity processing.

bool|int
doSave(int|string $id, EntityInterface $entity)

Performs storage-specific saving of the entity.

doPostSave(EntityInterface $entity, bool $update)

Performs post save entity processing.

restore(EntityInterface $entity)

Restores a previously saved entity.

buildPropertyQuery(QueryInterface $entity_query, array $values)

Builds an entity query.

loadByProperties(array $values = [])

Load entities by their property values.

bool
hasData()

Determines if the storage contains any data.

getQuery(string $conjunction = 'AND')

Gets an entity query instance.

getAggregateQuery(string $conjunction = 'AND')

Gets an aggregated query instance.

string
getQueryServiceName()

Gets the name of the service for the query for this entity storage.

array
getEntitiesByClass(array $entities)

Indexes the given array of entities by their class name and ID.

createInstance(ContainerInterface $container, EntityTypeInterface $entity_info)

Instantiates a new instance of this entity handler.

loadRevision(int|string $revision_id)

Load a specific entity revision.

deleteRevision(int $revision_id)

Delete a specific entity revision.

string
getPrefix()

Returns the prefix used to create the configuration name.

static string
getIDFromConfigName(string $config_name, string $config_prefix)

Extracts the configuration entity ID from the full configuration name.

array
mapToStorageRecord(EntityInterface $entity)

Maps from an entity object to the storage record.

importCreate(string $name, Config $new_config, Config $old_config)

Creates entities upon synchronizing configuration changes.

importUpdate(string $name, Config $new_config, Config $old_config)

Updates entities upon synchronizing configuration changes.

importDelete(string $name, Config $new_config, Config $old_config)

Delete entities upon synchronizing configuration changes.

importRename(string $old_name, Config $new_config, Config $old_config)

Renames entities upon synchronizing configuration changes.

createFromStorageRecord(array $values)

Creates a configuration entity from storage values.

ConfigEntityInterface
_doCreateFromStorageRecord(array $values, bool $is_syncing = FALSE)

Helps create a configuration entity from storage values.

updateFromStorageRecord(ConfigEntityInterface $entity, array $values)

Updates a configuration entity from storage values.

loadOverrideFree(mixed $id)

Loads one entity in their original form without overrides.

loadMultipleOverrideFree(array $ids = NULL)

Loads one or more entities in their original form without overrides.

deleteAssignedShortcutSets(ShortcutSetInterface $entity)

Delete shortcut sets assigned to users.

assignUser(ShortcutSetInterface $shortcut_set, $account)

Assigns a user to a particular shortcut set.

bool
unassignUser($account)

Unassigns a user from any shortcut set they may have been assigned to.

string
getAssignedToUser(User $account)

Get the name of the set assigned to this user.

int
countAssignedUsers(ShortcutSetInterface $shortcut_set)

Get the number of users who have this set assigned to them.

getDefaultSet(AccountInterface $account)

Gets the default shortcut set for a given user account.

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_info, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager, MemoryCacheInterface $memory_cache, Connection $connection)

Constructs a ShortcutSetStorageController object.

Parameters

EntityTypeInterface $entity_info

The entity info for the entity type.

ConfigFactoryInterface $config_factory

The config factory service.

UuidInterface $uuid_service

The UUID service.

ModuleHandlerInterface $module_handler

The module handler.

LanguageManagerInterface $language_manager

The language manager.

MemoryCacheInterface $memory_cache

The memory cache.

Connection $connection

The database connection.

string getEntityClass(string|null $bundle = NULL)

Retrieves the class name used to create the entity.

Parameters

string|null $bundle

(optional) A specific entity type bundle identifier. Can be omitted in the case of entity types without bundles, like User.

Return Value

string

The entity class name.

__get(string $name)

Warns subclasses not to directly access the deprecated entityClass property.

Remove this in Drupal 10.

Parameters

string $name

The name of the property to get.

See also

https://www.drupal.org/project/drupal/issues/3244802

void __set(string $name, mixed $value)

Warns subclasses not to directly set the deprecated entityClass property.

Remove this in Drupal 10.

Parameters

string $name

The name of the property to set.

mixed $value

The value to use.

Return Value

void

See also

https://www.drupal.org/project/drupal/issues/3244802

string getEntityTypeId()

Gets the entity type ID.

Return Value

string

The entity type ID.

EntityTypeInterface getEntityType()

Gets the entity type definition.

Return Value

EntityTypeInterface

Entity type definition.

protected string buildCacheId(int $id)

Builds the cache ID for the passed in entity ID.

Parameters

int $id

Entity ID for which the cache ID should be built.

Return Value

string

Cache ID that can be passed to the cache backend.

EntityInterface|null loadUnchanged(mixed $id)

Loads an unchanged entity from the database.

Parameters

mixed $id

The ID of the entity to load.

Return Value

EntityInterface|null

The unchanged entity, or NULL if the entity cannot be loaded.

resetCache(array $ids = NULL)

Resets the internal entity cache.

Parameters

array $ids

(optional) If specified, the cache is reset for the entities with the given ids only.

protected EntityInterface[] getFromStaticCache(array $ids)

Gets entities from the static cache.

Parameters

array $ids

If not empty, return entities that match these IDs.

Return Value

EntityInterface[]

Array of entities from the entity cache, keyed by entity ID.

protected setStaticCache(array $entities)

Stores entities in the static entity cache.

Parameters

array $entities

Entities to store in the cache.

protected invokeHook(string $hook, EntityInterface $entity)

Invokes a hook on behalf of the entity.

Parameters

string $hook

One of 'create', 'presave', 'insert', 'update', 'predelete', 'delete', or 'revision_delete'.

EntityInterface $entity

The entity object.

EntityInterface create(array $values = [])

Constructs a new entity object, without permanently saving it.

Parameters

array $values

(optional) An array of values to set, keyed by property name. If the entity type has bundles, the bundle key has to be specified.

Return Value

EntityInterface

A new entity object.

protected EntityInterface doCreate(array $values)

Performs storage-specific creation of entities.

Parameters

array $values

An array of values to set, keyed by property name.

Return Value

EntityInterface

EntityInterface|null load(mixed $id)

Loads one entity.

Parameters

mixed $id

The ID of the entity to load.

Return Value

EntityInterface|null

An entity object. NULL if no matching entity is found.

EntityInterface[] loadMultiple(array $ids = NULL)

Loads one or more entities.

Parameters

array $ids

An array of entity IDs, or NULL to load all entities.

Return Value

EntityInterface[]

An array of entity objects indexed by their IDs. Returns an empty array if no matching entities are found.

protected EntityInterface[] doLoadMultiple(array $ids = NULL)

Performs storage-specific loading of entities.

Override this method to add custom functionality directly after loading. This is always called, while self::postLoad() is only called when there are actual results.

Parameters

array $ids

(optional) An array of entity IDs, or NULL to load all entities.

Return Value

EntityInterface[]

Associative array of entities, keyed on the entity ID.

protected EntityInterface[] preLoad(array $ids = NULL)

Gathers entities from a 'preload' step.

Parameters

array $ids

If not empty, return entities that match these IDs. IDs that were found will be removed from the list.

Return Value

EntityInterface[]

Associative array of entities, keyed by the entity ID.

protected postLoad(array $entities)

Attaches data to entities upon loading.

If there are multiple bundle classes involved, each one gets a sub array with only the entities of the same bundle. If there's only a single bundle, the entity's postLoad() method will get a copy of the original $entities array.

Parameters

array $entities

Associative array of query results, keyed on the entity ID.

protected EntityInterface[] mapFromStorageRecords(array $records)

Maps from storage records to entity objects.

Parameters

array $records

Associative array of query results, keyed on the entity ID.

Return Value

EntityInterface[]

An array of entity objects implementing the EntityInterface.

protected bool has(int|string $id, EntityInterface $entity)

Determines if this entity already exists in storage.

Parameters

int|string $id

The original entity ID.

EntityInterface $entity

The entity being saved.

Return Value

bool

TRUE if this entity exists in storage, FALSE otherwise.

delete(array $entities)

Deletes permanently saved entities.

Parameters

array $entities

An array of entity objects to delete.

Exceptions

EntityStorageException

protected doDelete(EntityInterface[] $entities)

Performs storage-specific entity deletion.

Parameters

EntityInterface[] $entities

An array of entity objects to delete.

SAVED_NEW save(EntityInterface $entity)

Implements Drupal\Core\Entity\EntityStorageInterface::save().

Parameters

EntityInterface $entity

The entity to save.

Return Value

SAVED_NEW

or SAVED_UPDATED is returned depending on the operation performed.

Exceptions

EntityMalformedException

protected int|string doPreSave(EntityInterface $entity)

Performs presave entity processing.

Parameters

EntityInterface $entity

The saved entity.

Return Value

int|string

The processed entity identifier.

Exceptions

EntityStorageException

protected bool|int doSave(int|string $id, EntityInterface $entity)

Performs storage-specific saving of the entity.

Parameters

int|string $id

The original entity ID.

EntityInterface $entity

The entity to save.

Return Value

bool|int

If the record insert or update failed, returns FALSE. If it succeeded, returns SAVED_NEW or SAVED_UPDATED, depending on the operation performed.

protected doPostSave(EntityInterface $entity, bool $update)

Performs post save entity processing.

Parameters

EntityInterface $entity

The saved entity.

bool $update

Specifies whether the entity is being updated or created.

restore(EntityInterface $entity)

Restores a previously saved entity.

Note that the entity is assumed to be in a valid state for the storage, so the restore process does not invoke any hooks, nor does it perform any pre or post-save operations.

Parameters

EntityInterface $entity

The entity to restore.

Exceptions

EntityStorageException

protected buildPropertyQuery(QueryInterface $entity_query, array $values)

Builds an entity query.

Parameters

QueryInterface $entity_query

EntityQuery instance.

array $values

An associative array of properties of the entity, where the keys are the property names and the values are the values those properties must have.

EntityInterface[] loadByProperties(array $values = [])

Load entities by their property values.

Parameters

array $values

An associative array where the keys are the property names and the values are the values those properties must have.

Return Value

EntityInterface[]

An array of entity objects indexed by their ids.

bool hasData()

Determines if the storage contains any data.

Return Value

bool

TRUE if the storage contains data, FALSE if not.

QueryInterface getQuery(string $conjunction = 'AND')

Gets an entity query instance.

Parameters

string $conjunction

(optional) The logical operator for the query, either:

  • AND: all of the conditions on the query need to match.
  • OR: at least one of the conditions on the query need to match.

Return Value

QueryInterface

The query instance.

QueryAggregateInterface getAggregateQuery(string $conjunction = 'AND')

Gets an aggregated query instance.

Parameters

string $conjunction

(optional) The logical operator for the query, either:

  • AND: all of the conditions on the query need to match.
  • OR: at least one of the conditions on the query need to match.

Return Value

QueryAggregateInterface

The aggregated query object that can query the given entity type.

protected string getQueryServiceName()

Gets the name of the service for the query for this entity storage.

Return Value

string

The name of the service for the query for this entity storage.

protected array getEntitiesByClass(array $entities)

Indexes the given array of entities by their class name and ID.

Parameters

array $entities

The array of entities to index.

Return Value

array

An array of the passed-in entities, indexed by their class name and ID.

static EntityHandlerInterface createInstance(ContainerInterface $container, EntityTypeInterface $entity_info)

Instantiates a new instance of this entity handler.

This is a factory method that returns a new instance of this object. The factory should pass any needed dependencies into the constructor of this object, but not the container itself. Every call to this method must return a new instance of this object; that is, it may not implement a singleton.

Parameters

ContainerInterface $container

The service container this object should use.

EntityTypeInterface $entity_info

Return Value

EntityHandlerInterface

A new instance of the entity handler.

EntityInterface|null loadRevision(int|string $revision_id)

Load a specific entity revision.

Parameters

int|string $revision_id

The revision id.

Return Value

EntityInterface|null

The specified entity revision or NULL if not found.

deleteRevision(int $revision_id)

Delete a specific entity revision.

A revision can only be deleted if it's not the currently active one.

Parameters

int $revision_id

The revision id.

protected string getPrefix()

Returns the prefix used to create the configuration name.

The prefix consists of the config prefix from the entity type plus a dot for separating from the ID.

Return Value

string

The full configuration prefix, for example 'views.view.'.

static string getIDFromConfigName(string $config_name, string $config_prefix)

Extracts the configuration entity ID from the full configuration name.

Parameters

string $config_name

The full configuration name to extract the ID from; for example, 'views.view.archive'.

string $config_prefix

The config prefix of the configuration entity; for example, 'views.view'.

Return Value

string

The ID of the configuration entity.

protected array mapToStorageRecord(EntityInterface $entity)

Maps from an entity object to the storage record.

Parameters

EntityInterface $entity

The entity object.

Return Value

array

The record to store.

importCreate(string $name, Config $new_config, Config $old_config)

Creates entities upon synchronizing configuration changes.

Parameters

string $name

The name of the configuration object.

Config $new_config

A configuration object containing the new configuration data.

Config $old_config

A configuration object containing the old configuration data.

importUpdate(string $name, Config $new_config, Config $old_config)

Updates entities upon synchronizing configuration changes.

Parameters

string $name

The name of the configuration object.

Config $new_config

A configuration object containing the new configuration data.

Config $old_config

A configuration object containing the old configuration data.

Exceptions

ConfigImporterException

importDelete(string $name, Config $new_config, Config $old_config)

Delete entities upon synchronizing configuration changes.

Parameters

string $name

The name of the configuration object.

Config $new_config

A configuration object containing the new configuration data.

Config $old_config

A configuration object containing the old configuration data.

importRename(string $old_name, Config $new_config, Config $old_config)

Renames entities upon synchronizing configuration changes.

Parameters

string $old_name

The original name of the configuration object.

Config $new_config

A configuration object containing the new configuration data.

Config $old_config

A configuration object containing the old configuration data.

ConfigEntityInterface createFromStorageRecord(array $values)

Creates a configuration entity from storage values.

Allows the configuration entity storage to massage storage values before creating an entity.

Parameters

array $values

The array of values from the configuration storage.

Return Value

ConfigEntityInterface

The configuration entity.

protected ConfigEntityInterface _doCreateFromStorageRecord(array $values, bool $is_syncing = FALSE)

Helps create a configuration entity from storage values.

Allows the configuration entity storage to massage storage values before creating an entity.

Parameters

array $values

The array of values from the configuration storage.

bool $is_syncing

Is the configuration entity being created as part of a config sync.

Return Value

ConfigEntityInterface

The configuration entity.

See also

ConfigEntityStorageInterface::createFromStorageRecord
ImportableEntityStorageInterface::importCreate

ConfigEntityInterface updateFromStorageRecord(ConfigEntityInterface $entity, array $values)

Updates a configuration entity from storage values.

Allows the configuration entity storage to massage storage values before updating an entity.

Parameters

ConfigEntityInterface $entity

The configuration entity to update.

array $values

The array of values from the configuration storage.

Return Value

ConfigEntityInterface

The configuration entity.

EntityInterface|null loadOverrideFree(mixed $id)

Loads one entity in their original form without overrides.

Parameters

mixed $id

The ID of the entity to load.

Return Value

EntityInterface|null

An entity object. NULL if no matching entity is found.

EntityInterface[] loadMultipleOverrideFree(array $ids = NULL)

Loads one or more entities in their original form without overrides.

Parameters

array $ids

An array of entity IDs, or NULL to load all entities.

Return Value

EntityInterface[]

An array of entity objects indexed by their IDs. Returns an empty array if no matching entities are found.

deleteAssignedShortcutSets(ShortcutSetInterface $entity)

Delete shortcut sets assigned to users.

Parameters

ShortcutSetInterface $entity

Delete the user assigned sets belonging to this shortcut.

assignUser(ShortcutSetInterface $shortcut_set, $account)

Assigns a user to a particular shortcut set.

Parameters

ShortcutSetInterface $shortcut_set

An object representing the shortcut set.

$account

A user account that will be assigned to use the set.

bool unassignUser($account)

Unassigns a user from any shortcut set they may have been assigned to.

The user will go back to using whatever default set applies.

Parameters

$account

A user account that will be removed from the shortcut set assignment.

Return Value

bool

TRUE if the user was previously assigned to a shortcut set and has been successfully removed from it. FALSE if the user was already not assigned to any set.

string getAssignedToUser(User $account)

Get the name of the set assigned to this user.

Parameters

User $account

The user account.

Return Value

string

The name of the shortcut set assigned to this user.

int countAssignedUsers(ShortcutSetInterface $shortcut_set)

Get the number of users who have this set assigned to them.

Parameters

ShortcutSetInterface $shortcut_set

The shortcut to count the users assigned to.

Return Value

int

The number of users who have this set assigned to them.

ShortcutSetInterface getDefaultSet(AccountInterface $account)

Gets the default shortcut set for a given user account.

Parameters

AccountInterface $account

The user account whose default shortcut set will be returned.

Return Value

ShortcutSetInterface

An object representing the default shortcut set.