Skip to content

LayoutBuilder

Provides helpers for working with Layout Builder.


  • Full name: \Drupal\helper\LayoutBuilder

Properties

entityDisplayRepository

protected \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entityDisplayRepository

uuid

protected \Drupal\Component\Uuid\UuidInterface $uuid

routeMatch

protected \Drupal\Core\Routing\RouteMatchInterface $routeMatch

currentEntity

protected \Drupal\helper\CurrentEntity $currentEntity

memoryCache

protected \Drupal\Core\Cache\CacheBackendInterface $memoryCache

Methods

__construct

LayoutBuilder constructor.

public __construct(\Drupal\Core\Entity\EntityDisplayRepositoryInterface $entityDisplayRepository, \Drupal\Component\Uuid\UuidInterface $uuid, \Drupal\Core\Routing\RouteMatchInterface $routeMatch, \Drupal\helper\CurrentEntity $currentEntity, \Drupal\Core\Cache\CacheBackendInterface $memoryCache): mixed

Parameters:

Parameter Type Description
$entityDisplayRepository \Drupal\Core\Entity\EntityDisplayRepositoryInterface
The entity display repository.
$uuid \Drupal\Component\Uuid\UuidInterface
The UUID generator.
$routeMatch \Drupal\Core\Routing\RouteMatchInterface
The route match.
$currentEntity \Drupal\helper\CurrentEntity
The current entity helper.
$memoryCache \Drupal\Core\Cache\CacheBackendInterface
The memory cache.

getEntityBundleDisplay

Get the Layout Builder display for an entity type and bundle.

public getEntityBundleDisplay(\Drupal\Core\Entity\FieldableEntityInterface $entity, string $view_mode = \Drupal\Core\Entity\EntityDisplayRepositoryInterface::DEFAULT_DISPLAY_MODE): \Drupal\layout_builder\Entity\LayoutEntityDisplayInterface|null

Parameters:

Parameter Type Description
$entity \Drupal\Core\Entity\FieldableEntityInterface
The entity.
$view_mode string
(optional) The view mode.

Return Value:

The Layout Builder display if available, otherwise NULL.


isDisplayLayoutBuilderEnabled

Checks to see if an entity view display is using Layout Builder.

public isDisplayLayoutBuilderEnabled(\Drupal\Core\Entity\Display\EntityViewDisplayInterface $display): bool

Parameters:

Parameter Type Description
$display \Drupal\Core\Entity\Display\EntityViewDisplayInterface
The entity view display.

Return Value:

TRUE if the display is using Layout Builder, FALSE otherwise.


isEntityLayoutEnabled

Checks if an entity is using layout builder or not.

public isEntityLayoutEnabled(\Drupal\Core\Entity\FieldableEntityInterface $entity, bool $check_if_can_override = false): bool

Parameters:

Parameter Type Description
$entity \Drupal\Core\Entity\FieldableEntityInterface
The entity.
$check_if_can_override bool
A boolean to check if the layout can also be overridden for the entity.

Return Value:

TRUE if the entity has layout builder enabled.


isEntityLayoutOverridden

Checks if an entity is using an overridden layout builder or not.

public isEntityLayoutOverridden(\Drupal\Core\Entity\FieldableEntityInterface $entity): bool

Parameters:

Parameter Type Description
$entity \Drupal\Core\Entity\FieldableEntityInterface
The entity.

Return Value:

TRUE if the entity has an overridden layout.


shouldEditLayout

Checks if an entity's layout is overridden or the default layout is empty.

public shouldEditLayout(\Drupal\Core\Entity\FieldableEntityInterface $entity): bool

Parameters:

Parameter Type Description
$entity \Drupal\Core\Entity\FieldableEntityInterface
The entity.

Return Value:

TRUE if the entity has an overridden layout or its default layout is empty.


isLayoutEmpty

Checks if a layout has no components configured for display.

public isLayoutEmpty(\Drupal\layout_builder\SectionListInterface $layout): bool

Parameters:

Parameter Type Description
$layout \Drupal\layout_builder\SectionListInterface
The layout section list.

Return Value:

TRUE if none of the sections in the layout have any components, or FALSE otherwise.


isLayoutPage

Determines if the current page is a layout builder page.

public isLayoutPage(): bool

Return Value:

TRUE if the current page is a layout builder page, or FALSE otherwise.


setEntityLayout

Updates the overridden layout for an entity.

public setEntityLayout(\Drupal\Core\Entity\FieldableEntityInterface $entity, array $data): void

Parameters:

Parameter Type Description
$entity \Drupal\Core\Entity\FieldableEntityInterface
The entity.
$data array
The layout data.

sectionListGetComponentsByPluginId

Checks if a layout builder section list has a plugin.

public static sectionListGetComponentsByPluginId(\Drupal\layout_builder\SectionListInterface $sectionList, string $plugin_id): \Drupal\layout_builder\SectionComponent[]
  • This method is static. Parameters:
Parameter Type Description
$sectionList \Drupal\layout_builder\SectionListInterface
The Layout builder section list.
$plugin_id string
The plugin ID to find.

Return Value:

The section components that matched.


extractSectionListPlugins

Extract plugins from a section list.

public static extractSectionListPlugins(\Drupal\layout_builder\SectionListInterface $sectionList, bool $plugin_instance = false): array
  • This method is static. Parameters:
Parameter Type Description
$sectionList \Drupal\layout_builder\SectionListInterface
The Layout builder section list.
$plugin_instance bool
To return the plugins as objects instead of IDs.

Return Value:

A nested array of layout and block plugin IDs.