class EntityLazyLoadContext in Page Manager 8
Same name and namespace in other branches
- 8.4 src/Context/EntityLazyLoadContext.php \Drupal\page_manager\Context\EntityLazyLoadContext
@todo.
Hierarchy
- class \Drupal\Component\Plugin\Context\Context implements ContextInterface
- class \Drupal\Core\Plugin\Context\Context implements ContextInterface uses DependencySerializationTrait, TypedDataTrait
- class \Drupal\page_manager\Context\EntityLazyLoadContext
- class \Drupal\Core\Plugin\Context\Context implements ContextInterface uses DependencySerializationTrait, TypedDataTrait
Expanded class hierarchy of EntityLazyLoadContext
2 files declare their use of EntityLazyLoadContext
- ContextMapper.php in src/
ContextMapper.php - Contains \Drupal\page_manager\ContextMapper.
- ContextMapperTest.php in tests/
src/ Unit/ ContextMapperTest.php - Contains \Drupal\Tests\page_manager\Unit\ContextMapperTest.
File
- src/
Context/ EntityLazyLoadContext.php, line 17 - Contains \Drupal\page_manager\Context\EntityLazyLoadContext.
Namespace
Drupal\page_manager\ContextView source
class EntityLazyLoadContext extends Context {
/**
* The entity UUID.
*
* @var string
*/
protected $uuid;
/**
* The entity repository.
*
* @var \Drupal\Core\Entity\EntityRepositoryInterface
*/
protected $entityRepository;
/**
* Construct an EntityLazyLoadContext object.
*
* @param \Drupal\Core\Plugin\Context\ContextDefinitionInterface $context_definition
* The context definition.
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository.
* @param string $uuid
* The UUID of the entity.
*/
public function __construct(ContextDefinitionInterface $context_definition, EntityRepositoryInterface $entity_repository, $uuid) {
parent::__construct($context_definition);
$this->entityRepository = $entity_repository;
$this->uuid = $uuid;
}
/**
* {@inheritdoc}
*/
public function getContextValue() {
if (!$this->contextData) {
$entity_type_id = substr($this->contextDefinition
->getDataType(), 7);
$this
->setContextValue($this->entityRepository
->loadEntityByUuid($entity_type_id, $this->uuid));
}
return parent::getContextValue();
}
/**
* {@inheritdoc}
*/
public function hasContextValue() {
// Ensure that the entity is loaded before checking if it exists.
if (!$this->contextData) {
$this
->getContextValue();
}
return parent::hasContextValue();
}
}
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:: |
protected | function | Sets the context value. | |
Context:: |
public | function |
Validates the set context value. Overrides Context:: |
|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
EntityLazyLoadContext:: |
protected | property | The entity repository. | |
EntityLazyLoadContext:: |
protected | property | The entity UUID. | |
EntityLazyLoadContext:: |
public | function |
Gets the context value. Overrides Context:: |
|
EntityLazyLoadContext:: |
public | function |
Returns whether the context has a value. Overrides Context:: |
|
EntityLazyLoadContext:: |
public | function |
Construct an EntityLazyLoadContext object. Overrides Context:: |
|
TypedDataTrait:: |
protected | property | The typed data manager used for creating the data types. | |
TypedDataTrait:: |
public | function | Gets the typed data manager. | 2 |
TypedDataTrait:: |
public | function | Sets the typed data manager. | 2 |