Drupal\helper\LayoutBuilder
Provides helpers for working with Layout Builder.
Methods
| Name | Description |
|---|---|
| __construct | LayoutBuilder constructor. |
| extractSectionListPlugins | Extract plugins from a section list. |
| getEntityBundleDisplay | Get the Layout Builder display for an entity type and bundle. |
| isDisplayLayoutBuilderEnabled | Checks to see if an entity view display is using Layout Builder. |
| isEntityLayoutEnabled | Checks if an entity is using layout builder or not. |
| isEntityLayoutOverridden | Checks if an entity is using an overridden layout builder or not. |
| isLayoutEmpty | Checks if a layout has no components configured for display. |
| sectionListGetComponentsByPluginId | Checks if a layout builder section list has a plugin. |
| setEntityLayout | Updates the overridden layout for an entity. |
| shouldEditLayout | Checks if an entity's layout is overridden or the default layout is empty. |
LayoutBuilder::__construct
Description
public __construct (\Drupal\Core\Entity\EntityDisplayRepositoryInterface $entityDisplayRepository, \Drupal\Component\Uuid\UuidInterface $uuid)
LayoutBuilder constructor.
Parameters
(\Drupal\Core\Entity\EntityDisplayRepositoryInterface) $entityDisplayRepository:
The entity display repository.(\Drupal\Component\Uuid\UuidInterface) $uuid:
The UUID generator.
Return Values
void
LayoutBuilder::extractSectionListPlugins
Description
public static extractSectionListPlugins (\Drupal\layout_builder\SectionListInterface $sectionList, bool $plugin_instance)
Extract plugins from a section list.
Parameters
(\Drupal\layout_builder\SectionListInterface) $sectionList:
The Layout builder section list.(bool) $plugin_instance:
To return the plugins as objects instead of IDs.
Return Values
array
A nested array of layout and block plugin IDs.
LayoutBuilder::getEntityBundleDisplay
Description
public getEntityBundleDisplay (\Drupal\Core\Entity\FieldableEntityInterface $entity, string $view_mode)
Get the Layout Builder display for an entity type and bundle.
Parameters
(\Drupal\Core\Entity\FieldableEntityInterface) $entity:
The entity.(string) $view_mode:
(optional) The view mode.
Return Values
\Drupal\layout_builder\Entity\LayoutEntityDisplayInterface|null
The Layout Builder display if available, otherwise NULL.
LayoutBuilder::isDisplayLayoutBuilderEnabled
Description
public isDisplayLayoutBuilderEnabled (\Drupal\Core\Entity\Display\EntityViewDisplayInterface $display)
Checks to see if an entity view display is using Layout Builder.
Parameters
(\Drupal\Core\Entity\Display\EntityViewDisplayInterface) $display:
The entity view display.
Return Values
bool
TRUE if the display is using Layout Builder, FALSE otherwise.
LayoutBuilder::isEntityLayoutEnabled
Description
public isEntityLayoutEnabled (\Drupal\Core\Entity\FieldableEntityInterface $entity, bool $check_if_can_override)
Checks if an entity is using layout builder or not.
Parameters
(\Drupal\Core\Entity\FieldableEntityInterface) $entity:
The entity.(bool) $check_if_can_override:
A boolean to check if the layout can also be overridden for the entity.
Return Values
bool
TRUE if the entity has layout builder enabled.
LayoutBuilder::isEntityLayoutOverridden
Description
public isEntityLayoutOverridden (\Drupal\Core\Entity\FieldableEntityInterface $entity)
Checks if an entity is using an overridden layout builder or not.
Parameters
(\Drupal\Core\Entity\FieldableEntityInterface) $entity:
The entity.
Return Values
bool
TRUE if the entity has an overridden layout.
LayoutBuilder::isLayoutEmpty
Description
public isLayoutEmpty (\Drupal\layout_builder\SectionListInterface $layout)
Checks if a layout has no components configured for display.
Parameters
(\Drupal\layout_builder\SectionListInterface) $layout:
The layout section list.
Return Values
bool|null
TRUE if the entity layout can be overridden and the default layout
is empty, FALSE if the default layout is not empty, and NULL otherwise.
LayoutBuilder::sectionListGetComponentsByPluginId
Description
public static sectionListGetComponentsByPluginId (\Drupal\layout_builder\SectionListInterface $sectionList, string $plugin_id)
Checks if a layout builder section list has a plugin.
Parameters
(\Drupal\layout_builder\SectionListInterface) $sectionList:
The Layout builder section list.(string) $plugin_id:
The plugin ID to find.
Return Values
\Drupal\layout_builder\SectionComponent[]
The section components that matched.
LayoutBuilder::setEntityLayout
Description
public setEntityLayout (\Drupal\Core\Entity\FieldableEntityInterface $entity, array $data)
Updates the overridden layout for an entity.
Parameters
(\Drupal\Core\Entity\FieldableEntityInterface) $entity:
The entity.(array) $data:
The layout data.
Return Values
void
LayoutBuilder::shouldEditLayout
Description
public shouldEditLayout (\Drupal\Core\Entity\FieldableEntityInterface $entity)
Checks if an entity's layout is overridden or the default layout is empty.
Parameters
(\Drupal\Core\Entity\FieldableEntityInterface) $entity:
The entity.
Return Values
bool
TRUE if the entity has an overridden layout or its default layout is
empty.