public function Library::setContext in Layout builder library 8
Set a context on this plugin.
Parameters
string $name: The name of the context in the plugin configuration.
\Drupal\Component\Plugin\Context\ContextInterface $context: The context object to set.
Overrides ContextAwarePluginBase::setContext
File
- src/
Plugin/ SectionStorage/ Library.php, line 286
Class
- Library
- Defines a class for library based layout storage.
Namespace
Drupal\layout_library\Plugin\SectionStorageCode
public function setContext($name, ComponentContextInterface $context) {
$value = $context
->getContextValue();
// This cannot be done with constraints because the context handler does not
// currently validate optional context definitions.
if ($name === 'entity' && $value instanceof FieldableEntityInterface && $value
->hasField('layout_selection') && !$value
->get('layout_selection')
->isEmpty()) {
$name = 'layout';
$context = EntityContext::fromEntity($value
->get('layout_selection')->entity);
}
parent::setContext($name, $context);
}