class LayoutOverrideFieldHelper
Provides methods to help with entities using Layout Builder.
Hierarchy
- class \Drupal\layout_builder\LayoutOverrideFieldHelper implements \Drupal\Core\DependencyInjection\ContainerInjectionInterface uses \Drupal\layout_builder\LayoutEntityHelperTrait
Expanded class hierarchy of LayoutOverrideFieldHelper
1 file declares its use of LayoutOverrideFieldHelper
- LayoutBuilderHooks.php in core/
modules/ layout_builder/ src/ Hook/ LayoutBuilderHooks.php
File
-
core/
modules/ layout_builder/ src/ LayoutOverrideFieldHelper.php, line 16
Namespace
Drupal\layout_builderView source
class LayoutOverrideFieldHelper implements ContainerInjectionInterface {
use LayoutEntityHelperTrait;
/**
* Constructs a new LayoutOverrideFieldHelper.
*/
public function __construct(protected SectionStorageManagerInterface $sectionStorageManager, protected LayoutTempstoreRepositoryInterface $layoutTempstoreRepository) {
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) : static {
return new static($container->get('plugin.manager.layout_builder.section_storage'), $container->get('layout_builder.tempstore_repository'));
}
/**
* Updates a layout overrides's entity context when entity values change.
*
* @param \Drupal\Core\Entity\FieldableEntityInterface $entity
* The entity with the overridden layout.
*/
public function updateTempstoreEntityContext(FieldableEntityInterface $entity) : void {
if ($section_storage = $this->getOverridesSectionStorageForEntity($entity)) {
// This is only necessary if there is a layout override in the tempstore.
if ($this->layoutTempstoreRepository
->has($section_storage)) {
/** @var \Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorageInterface $override_temp_store */
$override_temp_store = $this->layoutTempstoreRepository
->get($section_storage);
// Get the entity currently in the tempstore's entity context.
$stored_entity = $override_temp_store->getContextValue('entity');
// Update the tempstore entity context with a copy of the new entity,
// but retain the value of the layout field from the tempstore.
$updated_entity = $entity;
$updated_entity->{OverridesSectionStorage::FIELD_NAME} = $stored_entity->{OverridesSectionStorage::FIELD_NAME};
$override_temp_store->setContextValue('entity', $updated_entity);
$this->layoutTempstoreRepository
->set($override_temp_store);
}
}
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
LayoutEntityHelperTrait::$sectionStorageManager | protected | property | The section storage manager. | 1 | |
LayoutEntityHelperTrait::getEntitySections | protected | function | Gets the sections for an entity if any. | ||
LayoutEntityHelperTrait::getInlineBlockComponents | protected | function | Gets components that have Inline Block plugins. | ||
LayoutEntityHelperTrait::getInlineBlockRevisionIdsInSections | protected | function | Gets revision IDs for layout sections. | ||
LayoutEntityHelperTrait::getOverridesSectionStorageForEntity | public | function | Gets the overrides section storage for an entity. | ||
LayoutEntityHelperTrait::getSectionStorageContextsForEntity | public | function | Gets the section storage contexts for an entity. | ||
LayoutEntityHelperTrait::getSectionStorageForEntity | protected | function | Gets the section storage for an entity. | ||
LayoutEntityHelperTrait::isLayoutCompatibleEntity | protected | function | Determines if an entity can have a layout. | ||
LayoutEntityHelperTrait::originalEntityUsesDefaultStorage | protected | function | Determines if the original entity used the default section storage. | ||
LayoutEntityHelperTrait::sectionStorageManager | private | function | Gets the section storage manager. | 1 | |
LayoutOverrideFieldHelper::create | public static | function | Instantiates a new instance of this class. | Overrides ContainerInjectionInterface::create | |
LayoutOverrideFieldHelper::updateTempstoreEntityContext | public | function | Updates a layout overrides's entity context when entity values change. | ||
LayoutOverrideFieldHelper::__construct | public | function | Constructs a new LayoutOverrideFieldHelper. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.