Entity deprecated
abstract class Entity extends EntityBase (View source)
deprecated
Defines a base entity class.
Traits
Trait for \Drupal\Core\Cache\RefinableCacheableDependencyInterface.
Provides dependency injection friendly methods for serialization.
Trait for \Drupal\Core\Cache\CacheableDependencyInterface.
Properties
| protected string[] | $cacheContexts | Cache contexts. |
from CacheableDependencyTrait |
| protected string[] | $cacheTags | Cache tags. |
from CacheableDependencyTrait |
| protected int | $cacheMaxAge | Cache max-age. |
from CacheableDependencyTrait |
| 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 string | $entityTypeId | The entity type. |
from EntityBase |
| protected bool | $enforceIsNew | Boolean indicating whether the entity should be forced to be new. |
from EntityBase |
| protected ComplexDataInterface | $typedData | A typed data object wrapping this entity. |
from EntityBase |
Methods
Sets cacheability; useful for value object constructors.
Gets the entity type bundle info service.
Gets the URL object for the entity.
Gets the URL object for the entity.
Deprecated way of generating a link to the entity. See toLink().
Generates the HTML for a link to this entity.
Gets the public URL for this entity.
Gets an array of placeholders for this entity.
Gets a list of URI relationships supported by this entity.
Checks data value access.
Acts on a saved entity before the insert or update hook is invoked.
Changes the values of an entity before it is created.
Acts on entities before they are deleted and before hooks are invoked.
Acts on deleted entities before the delete hook is invoked.
Gets a list of entities referenced by this entity.
The list cache tags to invalidate for this entity.
Returns the cache tags that should be used to invalidate caches.
Loads one or more entities.
Constructs a new entity object, without permanently saving it.
Invalidates an entity's cache tags upon delete.
Gets a typed data object for this entity object.
Gets the key that is used to store configuration dependencies.
Details
protected $this
setCacheability(CacheableDependencyInterface $cacheability)
Sets cacheability; useful for value object constructors.
getCacheTags()
{@inheritdoc}
getCacheContexts()
{@inheritdoc}
getCacheMaxAge()
{@inheritdoc}
addCacheableDependency($other_object)
{@inheritdoc}
addCacheContexts(array $cache_contexts)
{@inheritdoc}
addCacheTags(array $cache_tags)
{@inheritdoc}
mergeCacheMaxAge($max_age)
{@inheritdoc}
__sleep()
{@inheritdoc}
__wakeup()
{@inheritdoc}
__construct(array $values, string $entity_type)
Constructs an Entity object.
protected EntityManagerInterface
entityManager()
deprecated
deprecated
Gets the entity manager.
protected EntityTypeManagerInterface
entityTypeManager()
Gets the entity type manager.
protected EntityTypeBundleInfoInterface
entityTypeBundleInfo()
Gets the entity type bundle info service.
protected LanguageManagerInterface
languageManager()
Gets the language manager.
protected UuidInterface
uuidGenerator()
Gets the UUID generator.
string|int|null
id()
Gets the identifier.
string|null
uuid()
Gets the entity UUID (Universally Unique Identifier).
The UUID is guaranteed to be unique and can be used to identify an entity across multiple systems.
bool
isNew()
Determines whether the entity is new.
Usually an entity is new if no ID exists for it yet. However, entities may be enforced to be new with existing IDs too.
$this
enforceIsNew(bool $value = TRUE)
Enforces an entity to be new.
Allows migrations to create entities with pre-defined IDs by forcing the entity to be new before saving.
string
getEntityTypeId()
Gets the ID of the type of the entity.
string
bundle()
Gets the bundle of the entity.
string|null
label()
Gets the label of the entity.
Url
urlInfo(string $rel = 'canonical', array $options = [])
Gets the URL object for the entity.
Url
toUrl(string $rel = 'canonical', array $options = [])
Gets the URL object for the entity.
The entity must have an id already. Content entities usually get their IDs by saving them.
URI templates might be set in the links array in an annotation, for example:
bool
hasLinkTemplate($rel)
Indicates if a link template exists for a given key.
protected array
linkTemplates()
Gets an array link templates.
string
link(string|null $text = NULL, string $rel = 'canonical', array $options = [])
Deprecated way of generating a link to the entity. See toLink().
Link
toLink(string|null $text = NULL, string $rel = 'canonical', array $options = [])
Generates the HTML for a link to this entity.
string
url(string $rel = 'canonical', array $options = [])
Gets the public URL for this entity.
protected array
urlRouteParameters(string $rel)
Gets an array of placeholders for this entity.
Individual entity classes may override this method to add additional placeholders if desired. If so, they should be sure to replicate the property caching logic.
string[]
uriRelationships()
Gets a list of URI relationships supported by this entity.
bool|AccessResultInterface
access(string $operation, AccountInterface $account = NULL, bool $return_as_object = FALSE)
Checks data value access.
LanguageInterface
language()
Gets the language of the entity.
int
save()
Saves an entity permanently.
When saving existing entities, the entity is assumed to be complete, partial updates of entities are not supported.
delete()
Deletes an entity permanently.
EntityInterface
createDuplicate()
Creates a duplicate of the entity.
EntityTypeInterface
getEntityType()
Gets the entity type definition.
preSave(EntityStorageInterface $storage)
Acts on an entity before the presave hook is invoked.
Used before the entity is saved and before invoking the presave hook. Note that in case of translatable content entities this callback is only fired on their current translation. It is up to the developer to iterate over all translations if needed. This is different from its counterpart in the Field API, FieldItemListInterface::preSave(), which is fired on all field translations automatically.
postSave(EntityStorageInterface $storage, bool $update = TRUE)
Acts on a saved entity before the insert or update hook is invoked.
Used after the entity is saved, but before invoking the insert or update hook. Note that in case of translatable content entities this callback is only fired on their current translation. It is up to the developer to iterate over all translations if needed.
static
preCreate(EntityStorageInterface $storage, array $values)
Changes the values of an entity before it is created.
Load defaults for example.
postCreate(EntityStorageInterface $storage)
Acts on a created entity before hooks are invoked.
Used after the entity is created, but before saving the entity and before any of the presave hooks are invoked.
See the @link entity_crud Entity CRUD topic @endlink for more information.
static
preDelete(EntityStorageInterface $storage, array $entities)
Acts on entities before they are deleted and before hooks are invoked.
Used before the entities are deleted and before invoking the delete hook.
static
postDelete(EntityStorageInterface $storage, array $entities)
Acts on deleted entities before the delete hook is invoked.
Used after the entities are deleted but before invoking the delete hook.
static
postLoad(EntityStorageInterface $storage, array $entities)
Acts on loaded entities.
EntityInterface[]
referencedEntities()
Gets a list of entities referenced by this entity.
protected string[]
getListCacheTagsToInvalidate()
The list cache tags to invalidate for this entity.
string[]
getCacheTagsToInvalidate()
Returns the cache tags that should be used to invalidate caches.
This will not return additional cache tags added through addCacheTags().
static EntityInterface|null
load(mixed $id)
Loads an entity.
static EntityInterface[]
loadMultiple(array $ids = NULL)
Loads one or more entities.
static EntityInterface
create(array $values = [])
Constructs a new entity object, without permanently saving it.
protected
invalidateTagsOnSave(bool $update)
Invalidates an entity's cache tags upon save.
static protected
invalidateTagsOnDelete(EntityTypeInterface $entity_type, array $entities)
Invalidates an entity's cache tags upon delete.
int|string|null
getOriginalId()
Gets the original ID.
$this
setOriginalId(int|string|null $id)
Sets the original ID.
array
toArray()
Gets an array of all property values.
ComplexDataInterface
getTypedData()
Gets a typed data object for this entity object.
The returned typed data object wraps this entity and allows dealing with entities based on the generic typed data API.
string
getConfigDependencyKey()
Gets the key that is used to store configuration dependencies.
string
getConfigDependencyName()
Gets the configuration dependency name.
Configuration entities can depend on content and configuration entities. They store an array of content and config dependency names in their "dependencies" key.
string
getConfigTarget()
Gets the configuration target identifier for the entity.
Used to supply the correct format for storing a reference targeting this entity in configuration.