function LayoutBuilder::buildAddSectionLink
Same name in other branches
- 9 core/modules/layout_builder/src/Element/LayoutBuilder.php \Drupal\layout_builder\Element\LayoutBuilder::buildAddSectionLink()
- 8.9.x core/modules/layout_builder/src/Element/LayoutBuilder.php \Drupal\layout_builder\Element\LayoutBuilder::buildAddSectionLink()
- 11.x core/modules/layout_builder/src/Element/LayoutBuilder.php \Drupal\layout_builder\Element\LayoutBuilder::buildAddSectionLink()
Builds a link to add a new section at a given delta.
Parameters
\Drupal\layout_builder\SectionStorageInterface $section_storage: The section storage.
int $delta: The delta of the section to splice.
Return value
array A render array for a link.
1 call to LayoutBuilder::buildAddSectionLink()
- LayoutBuilder::layout in core/
modules/ layout_builder/ src/ Element/ LayoutBuilder.php - Renders the Layout UI.
File
-
core/
modules/ layout_builder/ src/ Element/ LayoutBuilder.php, line 152
Class
- LayoutBuilder
- Defines a render element for building the Layout Builder UI.
Namespace
Drupal\layout_builder\ElementCode
protected function buildAddSectionLink(SectionStorageInterface $section_storage, $delta) {
$storage_type = $section_storage->getStorageType();
$storage_id = $section_storage->getStorageId();
// If the delta and the count are the same, it is either the end of the
// layout or an empty layout.
if ($delta === count($section_storage)) {
if ($delta === 0) {
$title = $this->t('Add section');
}
else {
$title = $this->t('Add section <span class="visually-hidden">at end of layout</span>');
}
}
else {
if ($delta === 0) {
$title = $this->t('Add section <span class="visually-hidden">at start of layout</span>');
}
else {
$title = $this->t('Add section <span class="visually-hidden">between @first and @second</span>', [
'@first' => $delta,
'@second' => $delta + 1,
]);
}
}
return [
'link' => [
'#type' => 'link',
'#title' => $title,
'#url' => Url::fromRoute('layout_builder.choose_section', [
'section_storage_type' => $storage_type,
'section_storage' => $storage_id,
'delta' => $delta,
], [
'attributes' => [
'class' => [
'use-ajax',
'layout-builder__link',
'layout-builder__link--add',
],
'data-dialog-type' => 'dialog',
'data-dialog-renderer' => 'off_canvas',
],
]),
],
'#type' => 'container',
'#attributes' => [
'class' => [
'layout-builder__add-section',
],
'data-layout-builder-highlight-id' => $this->sectionAddHighlightId($delta),
],
];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.