EntityContext
class EntityContext extends Context (View source)
Class to provide a specific entity context.
Traits
Wrapper methods for classes that needs typed data manager object.
Provides dependency injection friendly methods for serialization.
Properties
| protected mixed | $contextValue | The value of the context. |
from Context |
| protected ContextDefinitionInterface | $contextDefinition | The definition to which a context must conform. |
from Context |
| protected TypedDataManagerInterface | $typedDataManager | The typed data manager used for creating the data types. |
from TypedDataTrait |
| 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 TypedDataInterface | $contextData | The data associated with the context. |
from Context |
| protected CacheableMetadata | $cacheabilityMetadata | The cacheability metadata. |
from Context |
Methods
Create a context object.
Gets the provided definition that the context must conform to.
Adds a dependency on an object: merges its cacheability metadata.
Creates a new context with a different value.
Gets a context from an entity type ID.
Gets a context from an entity type.
Details
__construct(ContextDefinitionInterface $context_definition, mixed|null $context_value = NULL)
Create a context object.
mixed
getContextValue()
Gets the context value.
bool
hasContextValue()
Returns whether the context has a value.
ContextDefinitionInterface
getContextDefinition()
Gets the provided definition that the context must conform to.
array
getConstraints()
Gets a list of validation constraints.
ConstraintViolationListInterface
validate()
Validates the set context value.
$this
setTypedDataManager(TypedDataManagerInterface $typed_data_manager)
Sets the typed data manager.
TypedDataManagerInterface
getTypedDataManager()
Gets the typed data manager.
__sleep()
{@inheritdoc}
__wakeup()
{@inheritdoc}
protected
setContextValue(mixed $value)
Sets the context value.
TypedDataInterface
getContextData()
Gets the context value as typed data object.
$this
addCacheableDependency(CacheableDependencyInterface|mixed $dependency)
Adds a dependency on an object: merges its cacheability metadata.
For example, when a context depends on some configuration, an entity, or an access result, we must make sure their cacheability metadata is present on the response. This method makes doing that simple.
string[]
getCacheContexts()
The cache contexts associated with this object.
These identify a specific variation/representation of the object.
Cache contexts are tokens: placeholders that are converted to cache keys by the @cache_contexts_manager service. The replacement value depends on the request context (the current URL, language, and so on). They're converted before storing an object in cache.
string[]
getCacheTags()
The cache tags associated with this object.
When this object is modified, these cache tags will be invalidated.
int
getCacheMaxAge()
The maximum age for which this object may be cached.
static ContextInterface
createFromContext(ContextInterface $old_context, mixed $value)
Creates a new context with a different value.
static EntityContext
fromEntityTypeId(string $entity_type_id, string $label = NULL)
Gets a context from an entity type ID.
static EntityContext
fromEntityType(EntityTypeInterface $entity_type, string $label = NULL)
Gets a context from an entity type.
static EntityContext
fromEntity(EntityInterface $entity, string $label = NULL)
Gets a context object from an entity.