class ContextDeriver in GraphQL 8.3
Hierarchy
- class \Drupal\Component\Plugin\Derivative\DeriverBase implements DeriverInterface
- class \Drupal\graphql_core\Plugin\Deriver\Fields\ContextDeriver implements ContainerDeriverInterface
Expanded class hierarchy of ContextDeriver
File
- modules/
graphql_core/ src/ Plugin/ Deriver/ Fields/ ContextDeriver.php, line 12
Namespace
Drupal\graphql_core\Plugin\Deriver\FieldsView source
class ContextDeriver extends DeriverBase implements ContainerDeriverInterface {
/**
* The context repository service.
*
* @var \Drupal\Core\Plugin\Context\ContextRepositoryInterface
*/
protected $contextRepository;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $basePluginId) {
return new static($container
->get('graphql.context_repository'));
}
/**
* ContextDeriver constructor.
*
* @param \Drupal\Core\Plugin\Context\ContextRepositoryInterface $contextRepository
* The context repository service.
*/
public function __construct(ContextRepositoryInterface $contextRepository) {
$this->contextRepository = $contextRepository;
}
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($basePluginDefinition) {
if (empty($this->derivatives)) {
foreach ($this->contextRepository
->getAvailableContexts() as $id => $context) {
$this->derivatives[$id] = [
'name' => StringHelper::propCase($id, 'context'),
'context_id' => $id,
'type' => $context
->getContextDefinition()
->getDataType(),
];
// Add cache contexts, if available
if ($context instanceof CacheableDependencyInterface) {
$this->derivatives[$id]['response_cache_contexts'] = $context
->getCacheContexts();
}
// Add default base
$this->derivatives[$id] += $basePluginDefinition;
}
}
return parent::getDerivativeDefinitions($basePluginDefinition);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContextDeriver:: |
protected | property | The context repository service. | |
ContextDeriver:: |
public static | function |
Creates a new class instance. Overrides ContainerDeriverInterface:: |
|
ContextDeriver:: |
public | function |
Gets the definition of all derivatives of a base plugin. Overrides DeriverBase:: |
|
ContextDeriver:: |
public | function | ContextDeriver constructor. | |
DeriverBase:: |
protected | property | List of derivative definitions. | 1 |
DeriverBase:: |
public | function |
Gets the definition of a derivative plugin. Overrides DeriverInterface:: |