final class SettingsContextHandler in Core Context 8
Exposes contexts stored in an entity's third-party settings.
Hierarchy
- class \Drupal\core_context\SettingsContextHandler implements EntityContextHandlerInterface uses CacheableContextTrait
Expanded class hierarchy of SettingsContextHandler
2 files declare their use of SettingsContextHandler
- core_context.module in ./
core_context.module - core_context_test.module in tests/
modules/ core_context_test/ core_context_test.module
File
- src/
SettingsContextHandler.php, line 14
Namespace
Drupal\core_contextView source
final class SettingsContextHandler implements EntityContextHandlerInterface {
use CacheableContextTrait;
/**
* The context mapper service.
*
* @var \Drupal\ctools\ContextMapperInterface
*/
private $contextMapper;
/**
* SettingsContextHandler constructor.
*
* @param \Drupal\ctools\ContextMapperInterface $context_mapper
* The context mapper service.
*/
public function __construct(ContextMapperInterface $context_mapper) {
$this->contextMapper = $context_mapper;
}
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static($container
->get('ctools.context_mapper'));
}
/**
* {@inheritdoc}
*/
public function getContexts(EntityInterface $entity) {
assert($entity instanceof ThirdPartySettingsInterface);
$contexts = $entity
->getThirdPartySetting('core_context', 'contexts', []);
$contexts = $this->contextMapper
->getContextValues($contexts);
return $this
->applyCaching($contexts, $entity);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheableContextTrait:: |
private | function | Adds cache metadata to a set of contexts. | |
SettingsContextHandler:: |
private | property | The context mapper service. | |
SettingsContextHandler:: |
public static | function |
Instantiates a new instance of this entity handler. Overrides EntityHandlerInterface:: |
|
SettingsContextHandler:: |
public | function |
Returns all contexts attached to an entity. Overrides EntityContextHandlerInterface:: |
|
SettingsContextHandler:: |
public | function | SettingsContextHandler constructor. |