class EntityContext in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Plugin/Context/EntityContext.php \Drupal\Core\Plugin\Context\EntityContext
- 9 core/lib/Drupal/Core/Plugin/Context/EntityContext.php \Drupal\Core\Plugin\Context\EntityContext
Class to provide a specific entity context.
Hierarchy
- class \Drupal\Component\Plugin\Context\Context implements ContextInterface
- class \Drupal\Core\Plugin\Context\Context implements ContextInterface uses DependencySerializationTrait, TypedDataTrait
- class \Drupal\Core\Plugin\Context\EntityContext
- class \Drupal\Core\Plugin\Context\Context implements ContextInterface uses DependencySerializationTrait, TypedDataTrait
Expanded class hierarchy of EntityContext
17 files declare their use of EntityContext
- ConditionTestDualUserTest.php in core/
tests/ Drupal/ KernelTests/ Core/ Plugin/ Condition/ ConditionTestDualUserTest.php - ContextDefinitionTest.php in core/
tests/ Drupal/ KernelTests/ Core/ Plugin/ ContextDefinitionTest.php - ContextHandlerTest.php in core/
tests/ Drupal/ KernelTests/ Core/ Plugin/ ContextHandlerTest.php - CurrentUserContext.php in core/
modules/ user/ src/ ContextProvider/ CurrentUserContext.php - DefaultsSectionStorage.php in core/
modules/ layout_builder/ src/ Plugin/ SectionStorage/ DefaultsSectionStorage.php
File
- core/
lib/ Drupal/ Core/ Plugin/ Context/ EntityContext.php, line 11
Namespace
Drupal\Core\Plugin\ContextView source
class EntityContext extends Context {
/**
* Gets a context from an entity type ID.
*
* @param string $entity_type_id
* Entity type ID from which a definition will be derived.
* @param string $label
* (optional) The label of the context.
*
* @return static
*/
public static function fromEntityTypeId($entity_type_id, $label = NULL) {
$entity_type = \Drupal::entityTypeManager()
->getDefinition($entity_type_id);
return static::fromEntityType($entity_type, $label);
}
/**
* Gets a context from an entity type.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* Entity type from which a definition will be derived.
* @param string $label
* (optional) The label of the context.
*
* @return static
*/
public static function fromEntityType(EntityTypeInterface $entity_type, $label = NULL) {
$definition = EntityContextDefinition::fromEntityType($entity_type);
if ($label) {
$definition
->setLabel($label);
}
return new static($definition);
}
/**
* Gets a context object from an entity.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* Entity that provides a context.
* @param string $label
* (optional) The label of the context.
*
* @return static
*/
public static function fromEntity(EntityInterface $entity, $label = NULL) {
$context = static::fromEntityType($entity
->getEntityType(), $label);
$context
->setContextValue($entity);
return $context;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Context:: |
protected | property | The cacheability metadata. | |
Context:: |
protected | property | The data associated with the context. | |
Context:: |
protected | property |
The definition to which a context must conform. Overrides Context:: |
|
Context:: |
protected | property | The value of the context. | |
Context:: |
public | function |
Adds a dependency on an object: merges its cacheability metadata. Overrides ContextInterface:: |
|
Context:: |
public static | function |
Creates a new context with a different value. Overrides ContextInterface:: |
|
Context:: |
public | function |
The cache contexts associated with this object. Overrides CacheableDependencyInterface:: |
|
Context:: |
public | function |
The maximum age for which this object may be cached. Overrides CacheableDependencyInterface:: |
|
Context:: |
public | function |
The cache tags associated with this object. Overrides CacheableDependencyInterface:: |
|
Context:: |
public | function |
Gets a list of validation constraints. Overrides Context:: |
|
Context:: |
public | function |
Gets the context value as typed data object. Overrides ContextInterface:: |
|
Context:: |
public | function |
Gets the provided definition that the context must conform to. Overrides Context:: |
|
Context:: |
public | function |
Gets the context value. Overrides Context:: |
|
Context:: |
public | function |
Returns whether the context has a value. Overrides Context:: |
|
Context:: |
protected | function | Sets the context value. | |
Context:: |
public | function |
Validates the set context value. Overrides Context:: |
|
Context:: |
public | function |
Create a context object. Overrides Context:: |
|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
EntityContext:: |
public static | function | Gets a context object from an entity. | |
EntityContext:: |
public static | function | Gets a context from an entity type. | |
EntityContext:: |
public static | function | Gets a context from an entity type ID. | |
TypedDataTrait:: |
protected | property | The typed data manager used for creating the data types. | |
TypedDataTrait:: |
public | function | Gets the typed data manager. | 1 |
TypedDataTrait:: |
public | function | Sets the typed data manager. | 1 |