class EntityContext
Same name in other branches
- 9 core/lib/Drupal/Core/Plugin/Context/EntityContext.php \Drupal\Core\Plugin\Context\EntityContext
- 8.9.x core/lib/Drupal/Core/Plugin/Context/EntityContext.php \Drupal\Core\Plugin\Context\EntityContext
- 10 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 \Drupal\Component\Plugin\Context\ContextInterface
- class \Drupal\Core\Plugin\Context\Context extends \Drupal\Component\Plugin\Context\Context implements \Drupal\Core\Plugin\Context\ContextInterface uses \Drupal\Core\TypedData\TypedDataTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait
- class \Drupal\Core\Plugin\Context\EntityContext extends \Drupal\Core\Plugin\Context\Context
- class \Drupal\Core\Plugin\Context\Context extends \Drupal\Component\Plugin\Context\Context implements \Drupal\Core\Plugin\Context\ContextInterface uses \Drupal\Core\TypedData\TypedDataTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait
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
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.