ItemStorage
class ItemStorage extends SqlContentEntityStorage implements ItemStorageInterface (View source)
Defines the storage handler class for feed item entities.
This extends the base storage class, adding required special handling for feed item entities.
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 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 string | $uuidKey | Name of entity's UUID database table field, if it supports UUIDs. |
from EntityStorageBase |
| protected string|bool | $langcodeKey | The entity langcode key. |
from SqlContentEntityStorage |
| 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 string|bool | $bundleKey | The entity bundle key. |
from ContentEntityStorageBase |
| protected EntityFieldManagerInterface | $entityFieldManager | The entity field manager service. |
from ContentEntityStorageBase |
| protected EntityTypeBundleInfoInterface | $entityTypeBundleInfo | The entity bundle info. |
from ContentEntityStorageBase |
| protected CacheBackendInterface | $cacheBackend | Cache backend. |
from ContentEntityStorageBase |
| protected array | $latestRevisionIds | Stores the latest revision IDs for entities. |
from ContentEntityStorageBase |
| protected FieldStorageDefinitionInterface[] | $fieldStorageDefinitions | The entity type's field storage definitions. |
from SqlContentEntityStorage |
| protected TableMappingInterface | $tableMapping | The mapping of field columns to SQL tables. |
from SqlContentEntityStorage |
| protected string | $revisionKey | Name of entity's revision database table field, if it supports revisions. |
from SqlContentEntityStorage |
| protected string | $defaultLangcodeKey | The default language entity key. |
from SqlContentEntityStorage |
| protected string | $baseTable | The base table of the entity. |
from SqlContentEntityStorage |
| protected string | $revisionTable | The table that stores revisions, if the entity supports revisions. |
from SqlContentEntityStorage |
| protected string | $dataTable | The table that stores properties, if the entity has multilingual support. |
from SqlContentEntityStorage |
| protected string | $revisionDataTable | The table that stores revision field data if the entity supports revisions. |
from SqlContentEntityStorage |
| protected Connection | $database | Active database connection. |
from SqlContentEntityStorage |
| protected EntityStorageSchemaInterface | $storageSchema | The entity type's storage schema object. |
from SqlContentEntityStorage |
| protected LanguageManagerInterface | $languageManager | The language manager. |
from SqlContentEntityStorage |
| protected EntityTypeManagerInterface | $entityTypeManager | The entity type manager. |
from SqlContentEntityStorage |
| protected bool | $temporary | Whether this storage should use the temporary table mapping. |
from SqlContentEntityStorage |
Methods
Translates a string to the current language or to a given language.
Formats a string containing a count of items.
Returns the number of plurals supported by a given language.
Gets the string translation service.
Constructs a SqlContentEntityStorage object.
Retrieves the class name used to create the entity.
Warns subclasses not to directly access the deprecated entityClass property.
Warns subclasses not to directly set the deprecated entityClass property.
Builds the cache ID for the passed in entity ID.
Loads an unchanged entity from the database.
Gets entities from the static cache.
Constructs a new entity object, without permanently saving it.
Performs storage-specific creation of entities.
Loads one or more entities.
Performs storage-specific loading of entities.
Gathers entities from a 'preload' step.
Maps from storage records to entity objects, and attaches fields.
Load entities by their property values.
Gets an entity query instance.
Gets an aggregated query instance.
Gets the name of the service for the query for this entity storage.
Indexes the given array of entities by their class name and ID.
Instantiates a new instance of this entity handler.
Retrieves the bundle name for a provided class name.
Retrieves the bundle from an array of values.
Creates an entity with sample field values.
Initializes field values.
Checks whether any entity revision is translated.
Checks whether any stored entity revision is translated.
Constructs a new entity translation object, without permanently saving it.
Creates a new revision starting off from the specified entity object.
Returns an array of field names to skip when merging revision translations.
Returns the latest revision identifier for an entity.
Returns the latest revision affecting the specified translation.
Reacts to the creation of a field storage definition.
Reacts to the update of a field storage definition.
Reacts to the deletion of a field storage definition.
Reacts to the creation of a field.
Reacts to the update of a field.
Reacts to the deletion of a field.
Purges a batch of field data.
Reads values to be purged for a single field.
Removes field items from storage per entity during purge.
Performs final cleanup after all data of a field has been purged.
Load a specific entity revision.
Loads multiple entity revisions.
Actually loads revision field item values from the storage.
Writes entity field values to the storage.
Deletes entity field values from the storage.
Deletes field values of an entity revision from the storage.
Checks translation statuses and invoke the related hooks if needed.
Invokes hook_entity_storage_load().
Invokes a method on the Field objects within an entity.
Invokes the post save method on the Field objects within an entity.
Checks whether the field values changed compared to the original entity.
Populates the affected flag for all the revision translations.
Ensures integer entity key values are valid.
Gets entities from the persistent cache backend.
Stores entities in the persistent cache backend.
Gets the entity type's storage schema object.
Updates the internal list of field storage definitions.
Changes the temporary state of the storage.
Gets a table mapping for the entity's SQL tables.
Gets a table mapping for the specified entity type and storage definitions.
Gets entities from the storage.
Loads values for fields stored in the shared data tables.
Builds the query to load the entity.
Saves fields that use the shared tables.
Maps from an entity object to the storage record.
Checks whether a field column should be treated as serial.
Maps from an entity object to the storage record of the field data.
Loads values of fields stored in dedicated tables for a group of entities.
Saves values of fields that use dedicated tables.
Deletes values of fields in dedicated tables for all revisions.
Deletes values of fields in dedicated tables for all revisions.
Checks if the changes to the entity type requires storage schema changes.
Checks if the changes to the storage definition requires schema changes.
Checks if existing data would be lost if the schema changes were applied.
Checks if existing data would be lost if the schema changes were applied.
Reacts to the update of the entity type.
Reacts to the creation of the fieldable entity type.
Reacts to the update of a fieldable entity type.
Wraps a database schema exception into an entity storage exception.
Reacts to a bundle being created.
Reacts to a bundle being deleted.
Determines the number of entities with values for a given field.
Loads feed items from all feeds.
Loads feed items filtered by a feed.
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
protected
formatPlural($count, $singular, $plural, array $args = [], array $options = [])
Formats a string containing a count of items.
protected
getNumberOfPlurals($langcode = NULL)
Returns the number of plurals supported by a given language.
protected TranslationInterface
getStringTranslation()
Gets the string translation service.
$this
setStringTranslation(TranslationInterface $translation)
Sets the string translation service to use.
__sleep()
{@inheritdoc}
__wakeup()
{@inheritdoc}
protected ModuleHandlerInterface
moduleHandler()
Gets the module handler.
$this
setModuleHandler(ModuleHandlerInterface $module_handler)
Sets the module handler for this handler.
__construct(EntityTypeInterface $entity_type, Connection $database, EntityFieldManagerInterface $entity_field_manager, CacheBackendInterface $cache, LanguageManagerInterface $language_manager, MemoryCacheInterface $memory_cache, EntityTypeBundleInfoInterface $entity_type_bundle_info, EntityTypeManagerInterface $entity_type_manager)
Constructs a SqlContentEntityStorage 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.
EntityTypeInterface
getEntityType()
Gets the entity type definition.
protected string
buildCacheId(int $id)
Builds the cache ID for the passed in entity ID.
EntityInterface|null
loadUnchanged(mixed $id)
Loads an unchanged entity from the database.
resetCache(array $ids = NULL)
Resets the entity cache.
Content entities have both an in-memory static cache and a persistent cache. Use this method to clear all caches. To clear just the in-memory cache, use the 'entity.memory_cache' service.
protected EntityInterface[]
getFromStaticCache(array $ids)
Gets entities from the static cache.
protected
setStaticCache(array $entities)
Stores entities in the static entity cache.
protected
invokeHook(string $hook, EntityInterface $entity)
Invokes a hook on behalf of the entity.
EntityInterface
create(array $values = [])
Constructs a new entity object, without permanently saving it.
protected EntityInterface
doCreate(array $values)
Performs storage-specific creation of entities.
EntityInterface|null
load(mixed $id)
Loads one entity.
EntityInterface[]
loadMultiple(array $ids = NULL)
Loads one or more entities.
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.
protected EntityInterface[]
preLoad(array $ids = NULL)
Gathers entities from a 'preload' step.
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.
protected EntityInterface[]
mapFromStorageRecords(array $records, bool $load_from_revision = FALSE)
Maps from storage records to entity objects, and attaches fields.
protected bool
has(int|string $id, EntityInterface $entity)
Determines if this entity already exists in storage.
delete(array $entities)
Deletes permanently saved entities.
protected
doDelete(EntityInterface[] $entities)
Performs storage-specific entity deletion.
SAVED_NEW
save(EntityInterface $entity)
Saves the entity permanently.
protected int|string
doPreSave(EntityInterface $entity)
Performs presave entity processing.
protected bool|int
doSave(int|string $id, EntityInterface $entity)
Performs storage-specific saving of the entity.
protected
doPostSave(EntityInterface $entity, bool $update)
Performs post save entity processing.
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.
protected
buildPropertyQuery(QueryInterface $entity_query, array $values)
Builds an entity query.
EntityInterface[]
loadByProperties(array $values = [])
Load entities by their property values.
bool
hasData()
Determines if the storage contains any data.
QueryInterface
getQuery(string $conjunction = 'AND')
Gets an entity query instance.
QueryAggregateInterface
getAggregateQuery(string $conjunction = 'AND')
Gets an aggregated query instance.
protected string
getQueryServiceName()
Gets 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.
static EntityHandlerInterface
createInstance(ContainerInterface $container, EntityTypeInterface $entity_type)
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.
string|null
getBundleFromClass(string $class_name)
Retrieves the bundle name for a provided class name.
protected string|null
getBundleFromValues(array $values)
Retrieves the bundle from an array of values.
FieldableEntityInterface
createWithSampleValues(string|bool $bundle = FALSE, array $values = [])
Creates an entity with sample field values.
protected
initFieldValues(ContentEntityInterface $entity, array $values = [], array $field_names = [])
Initializes field values.
protected bool
isAnyRevisionTranslated(TranslatableInterface $entity)
Checks whether any entity revision is translated.
protected bool
isAnyStoredRevisionTranslated(TranslatableInterface $entity)
Checks whether any stored entity revision is translated.
A revisionable entity can have translations in a pending revision, hence the default revision may appear as not translated. This determines whether the entity has any translation in the storage and thus should be considered as multilingual.
ContentEntityInterface
createTranslation(ContentEntityInterface $entity, string $langcode, array $values = [])
Constructs a new entity translation object, without permanently saving it.
RevisionableInterface
createRevision(RevisionableInterface $entity, bool $default = TRUE, $keep_untranslatable_fields = NULL)
Creates a new revision starting off from the specified entity object.
protected array
getRevisionTranslationMergeSkippedFieldNames()
Returns an array of field names to skip when merging revision translations.
int|string|null
getLatestRevisionId(int|string $entity_id)
Returns the latest revision identifier for an entity.
int|string|null
getLatestTranslationAffectedRevisionId(int|string $entity_id, string $langcode)
Returns the latest revision affecting the specified translation.
onFieldStorageDefinitionCreate(FieldStorageDefinitionInterface $storage_definition)
Reacts to the creation of a field storage definition.
onFieldStorageDefinitionUpdate(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)
Reacts to the update of a field storage definition.
onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $storage_definition)
Reacts to the deletion of a field storage definition.
onFieldDefinitionCreate(FieldDefinitionInterface $field_definition)
Reacts to the creation of a field.
onFieldDefinitionUpdate(FieldDefinitionInterface $field_definition, FieldDefinitionInterface $original)
Reacts to the update of a field.
onFieldDefinitionDelete(FieldDefinitionInterface $field_definition)
Reacts to the deletion of a field.
Stored values should not be wiped at once, but marked as 'deleted' so that they can go through a proper purge process later on.
int
purgeFieldData(FieldDefinitionInterface $field_definition, int $batch_size)
Purges a batch of field data.
protected FieldItemListInterface[]
readFieldItemsToPurge(FieldDefinitionInterface $field_definition, $batch_size)
Reads values to be purged for a single field.
This method is called during field data purge, on fields for which onFieldDefinitionDelete() has previously run.
protected
purgeFieldItems(ContentEntityInterface $entity, FieldDefinitionInterface $field_definition)
Removes field items from storage per entity during purge.
finalizePurge(FieldStorageDefinitionInterface $storage_definition)
Performs final cleanup after all data of a field has been purged.
EntityInterface|null
loadRevision(int|string $revision_id)
Load a specific entity revision.
RevisionableInterface[]
loadMultipleRevisions(array $revision_ids)
Loads multiple entity revisions.
protected EntityInterface[]
doLoadMultipleRevisionsFieldItems(array $revision_ids)
Actually loads revision field item values from the storage.
protected
doSaveFieldItems(ContentEntityInterface $entity, array $names = [])
Writes entity field values to the storage.
This method is responsible for allocating entity and revision identifiers and updating the entity object with their values.
protected
doDeleteFieldItems(ContentEntityInterface[] $entities)
Deletes entity field values from the storage.
deleteRevision(int $revision_id)
Delete a specific entity revision.
A revision can only be deleted if it's not the currently active one.
protected
doDeleteRevisionFieldItems(ContentEntityInterface $revision)
Deletes field values of an entity revision from the storage.
protected
invokeTranslationHooks(ContentEntityInterface $entity)
Checks translation statuses and invoke the related hooks if needed.
protected
invokeStorageLoadHook(array $entities)
Invokes hook_entity_storage_load().
protected array
invokeFieldMethod(string $method, ContentEntityInterface $entity)
Invokes a method on the Field objects within an entity.
Any argument passed will be forwarded to the invoked method.
protected
invokeFieldPostSave(ContentEntityInterface $entity, bool $update)
Invokes the post save method on the Field objects within an entity.
protected bool
hasFieldValueChanged(FieldDefinitionInterface $field_definition, ContentEntityInterface $entity, ContentEntityInterface $original)
Checks whether the field values changed compared to the original entity.
protected
populateAffectedRevisionTranslations(ContentEntityInterface $entity)
Populates the affected flag for all the revision translations.
protected array
cleanIds(array $ids, string $entity_key = 'id')
Ensures integer entity key values are valid.
The identifier sanitization provided by this method has been introduced as Drupal used to rely on the database to facilitate this, which worked correctly with MySQL but led to errors with other DBMS such as PostgreSQL.
protected ContentEntityInterface[]
getFromPersistentCache(array $ids = NULL)
Gets entities from the persistent cache backend.
protected
setPersistentCache(ContentEntityInterface[] $entities)
Stores entities in the persistent cache backend.
protected
initTableLayout()
Initializes table name variables.
string
getBaseTable()
Gets the base table name.
string|false
getRevisionTable()
Gets the revision table name.
string|false
getDataTable()
Gets the data table name.
string|false
getRevisionDataTable()
Gets the revision data table name.
protected SqlContentEntityStorageSchema
getStorageSchema()
Gets the entity type's storage schema object.
setEntityType(EntityTypeInterface $entity_type)
| internal | Only to be used internally by Entity API. Expected to be removed by https://www.drupal.org/node/2274017. |
Updates the wrapped entity type definition.
setFieldStorageDefinitions(array $field_storage_definitions)
| internal | Only to be used internally by Entity API. |
Updates the internal list of field storage definitions.
setTableMapping(TableMappingInterface $table_mapping)
| internal | Only to be used internally by Entity API. Expected to be removed by https://www.drupal.org/node/2554235. |
Sets the wrapped table mapping definition.
setTemporary(bool $temporary)
| internal | Only to be used internally by Entity API. |
Changes the temporary state of the storage.
TableMappingInterface
getTableMapping(array $storage_definitions = NULL)
Gets a table mapping for the entity's SQL tables.
TableMappingInterface
getCustomTableMapping(ContentEntityTypeInterface $entity_type, array $storage_definitions, string $prefix = '')
| internal |
Gets a table mapping for the specified entity type and storage definitions.
protected ContentEntityInterface[]
getFromStorage(array $ids = NULL)
Gets entities from the storage.
protected
loadFromSharedTables(array $values, array $translations, bool $load_from_revision)
Loads values for fields stored in the shared data tables.
protected SelectInterface
buildQuery(array|null $ids, array|bool $revision_ids = FALSE)
Builds the query to load the entity.
This has full revision support. For entities requiring special queries, the class can be extended, and the default query can be constructed by calling parent::buildQuery(). This is usually necessary when the object being loaded needs to be augmented with additional data from another table, such as loading vocabulary machine name into terms, however it can also support $conditions on different tables.
protected
saveToSharedTables(ContentEntityInterface $entity, string $table_name = NULL, bool $new_revision = NULL)
Saves fields that use the shared tables.
protected object
mapToStorageRecord(ContentEntityInterface $entity, string $table_name = NULL)
Maps from an entity object to the storage record.
protected bool
isColumnSerial($table_name, $schema_name)
Checks whether a field column should be treated as serial.
protected object
mapToDataStorageRecord(EntityInterface $entity, string $table_name = NULL)
Maps from an entity object to the storage record of the field data.
protected int
saveRevision(ContentEntityInterface $entity)
Saves an entity revision.
protected
loadFromDedicatedTables(array $values, bool $load_from_revision)
Loads values of fields stored in dedicated tables for a group of entities.
protected
saveToDedicatedTables(ContentEntityInterface $entity, bool $update = TRUE, string[] $names = [])
Saves values of fields that use dedicated tables.
protected
deleteFromDedicatedTables(ContentEntityInterface $entity)
Deletes values of fields in dedicated tables for all revisions.
protected
deleteRevisionFromDedicatedTables(ContentEntityInterface $entity)
Deletes values of fields in dedicated tables for all revisions.
bool
requiresEntityStorageSchemaChanges(EntityTypeInterface $entity_type, EntityTypeInterface $original)
Checks if the changes to the entity type requires storage schema changes.
bool
requiresFieldStorageSchemaChanges(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)
Checks if the changes to the storage definition requires schema changes.
bool
requiresEntityDataMigration(EntityTypeInterface $entity_type, EntityTypeInterface $original)
Checks if existing data would be lost if the schema changes were applied.
If there are no schema changes needed, then no data needs to be migrated, but it is not the responsibility of this function to recheck what requiresEntityStorageSchemaChanges() checks. Rather, the meaning of what this function returns when requiresEntityStorageSchemaChanges() returns FALSE is undefined. Callers are expected to only call this function when requiresEntityStorageSchemaChanges() is TRUE.
This function can return FALSE if any of these conditions apply:
- There are no existing entities for the entity type.
- There are existing entities, but the schema changes can be applied without losing their data (e.g., if the schema changes can be performed by altering tables rather than dropping and recreating them).
- The only entity data that would be lost are ones that are not valid for the new definition (e.g., if changing an entity type from revisionable to non-revisionable, then it's okay to drop data for the non-default revision).
When this function returns FALSE, site administrators will be unable to perform an automated update, and will instead need to perform a site migration or invoke some custom update process.
bool
requiresFieldDataMigration(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)
Checks if existing data would be lost if the schema changes were applied.
If there are no schema changes needed, then no data needs to be migrated, but it is not the responsibility of this function to recheck what requiresFieldStorageSchemaChanges() checks. Rather, the meaning of what this function returns when requiresFieldStorageSchemaChanges() returns FALSE is undefined. Callers are expected to only call this function when requiresFieldStorageSchemaChanges() is TRUE.
This function can return FALSE if any of these conditions apply:
- There are no existing entities for the entity type to which this field is attached.
- There are existing entities, but none with existing values for this field.
- There are existing field values, but the schema changes can be applied without losing them (e.g., if the schema changes can be performed by altering tables rather than dropping and recreating them).
- The only field values that would be lost are ones that are not valid for the new definition (e.g., if changing a field from revisionable to non-revisionable, then it's okay to drop data for the non-default revision).
When this function returns FALSE, site administrators will be unable to perform an automated update, and will instead need to perform a site migration or invoke some custom update process.
onEntityTypeCreate(EntityTypeInterface $entity_type)
Reacts to the creation of the entity type.
onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original)
Reacts to the update of the entity type.
onEntityTypeDelete(EntityTypeInterface $entity_type)
Reacts to the deletion of the entity type.
onFieldableEntityTypeCreate(EntityTypeInterface $entity_type, array $field_storage_definitions)
Reacts to the creation of the fieldable entity type.
onFieldableEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original, array $field_storage_definitions, array $original_field_storage_definitions, array $sandbox = NULL)
Reacts to the update of a fieldable entity type.
protected
wrapSchemaException(callable $callback)
Wraps a database schema exception into an entity storage exception.
onBundleCreate(string $bundle, string $entity_type_id)
Reacts to a bundle being created.
onBundleDelete(string $bundle, string $entity_type_id)
Reacts to a bundle being deleted.
This method runs before fields are deleted.
bool|int
countFieldData(FieldStorageDefinitionInterface $storage_definition, bool $as_bool = FALSE)
Determines the number of entities with values for a given field.
int
getItemCount(FeedInterface $feed)
Returns the count of the items in a feed.
ItemInterface[]
loadAll(int $limit = NULL)
Loads feed items from all feeds.
ItemInterface[]
loadByFeed(int $fid, int $limit = NULL)
Loads feed items filtered by a feed.
protected ItemInterface[]
executeFeedItemQuery(QueryInterface $query, int $limit)
Helper method to execute an item query.