protected function PdbBlockDeriver::createContexts in Decoupled Blocks 8
Creates the context definitions required by a block plugin.
Parameters
array $contexts: Contexts as defined in component label.
Return value
\Drupal\Core\Plugin\Context\ContextDefinition[] Array of context to be used by block module.
1 call to PdbBlockDeriver::createContexts()
- PdbBlockDeriver::getDerivativeDefinitions in src/
Plugin/ Derivative/ PdbBlockDeriver.php - Gets the definition of all derivatives of a base plugin.
File
- src/
Plugin/ Derivative/ PdbBlockDeriver.php, line 76
Class
- PdbBlockDeriver
- Provides a deriver for pdb blocks.
Namespace
Drupal\pdb\Plugin\DerivativeCode
protected function createContexts(array $contexts) {
$contexts_definitions = [];
// Support for old node entity context defintion.
// "entity: node" must now be defined as "entity: entity:node".
if (isset($contexts['entity']) && $contexts['entity'] === 'node') {
$contexts['entity'] = 'entity:node';
}
foreach ($contexts as $context_id => $context_type) {
if (strpos($context_type, 'entity:') === 0) {
// Use dedicated entity context class for entity contexts.
$contexts_definitions[$context_id] = new EntityContextDefinition($context_type);
}
else {
// Otherwise, use common context class.
$contexts_definitions[$context_id] = new ContextDefinition($context_type);
}
}
return $contexts_definitions;
}