Skip to content

Drupal\helper\LayoutBuilder

Provides helpers for working with Layout Builder.

Methods

Name Description
__construct LayoutBuilder constructor.
extractSectionListPlugins Extract plugins from a section list.
isEntityLayoutEnabled Checks if an entity is using layout builder or not.
isEntityLayoutOverridden Checks if an entity is using an overridden layout builder or not.
sectionListGetComponentsByPluginId Checks if a layout builder section list has a plugin.
setEntityLayout Updates the overriden layout for an entity.

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::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::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 overriden layout for an entity.

Parameters

  • (\Drupal\Core\Entity\FieldableEntityInterface) $entity : The entity.
  • (array) $data : The layout data.

Return Values

void