abstract class ContextProviderBase in Core Context 8
Provides a base class for context providers.
Hierarchy
- class \Drupal\core_context\ContextProvider\ContextProviderBase implements ContextProviderInterface
Expanded class hierarchy of ContextProviderBase
File
- src/
ContextProvider/ ContextProviderBase.php, line 12
Namespace
Drupal\core_context\ContextProviderView source
abstract class ContextProviderBase implements ContextProviderInterface {
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* ContextProviderBase constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
/**
* Extracts contexts from an entity.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity from which to extract contexts.
*
* @return \Drupal\Component\Plugin\Context\ContextInterface[]
* The contexts extracted from the entity.
*/
protected function getContextsFromEntity(EntityInterface $entity) {
$entity_type = $entity
->getEntityType();
if ($entity_type
->hasHandlerClass('context')) {
return $this->entityTypeManager
->getHandler($entity_type
->id(), 'context')
->getContexts($entity);
}
return [];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContextProviderBase:: |
protected | property | The entity type manager service. | |
ContextProviderBase:: |
protected | function | Extracts contexts from an entity. | |
ContextProviderBase:: |
public | function | ContextProviderBase constructor. | 1 |
ContextProviderInterface:: |
public | function | Gets all available contexts for the purposes of configuration. | 5 |
ContextProviderInterface:: |
public | function | Gets runtime context values for the given context IDs. | 5 |