class LayoutBuilderUX in Layout Builder UX 8
Alters the Layout Builder UI element.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\Core\Render\Element\RenderElement implements ElementInterface
- class \Drupal\layout_builder\Element\LayoutBuilder implements ContainerFactoryPluginInterface uses AjaxHelperTrait, LayoutBuilderContextTrait, LayoutBuilderHighlightTrait
- class \Drupal\lb_ux\Element\LayoutBuilderUX
- class \Drupal\layout_builder\Element\LayoutBuilder implements ContainerFactoryPluginInterface uses AjaxHelperTrait, LayoutBuilderContextTrait, LayoutBuilderHighlightTrait
- class \Drupal\Core\Render\Element\RenderElement implements ElementInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of LayoutBuilderUX
1 file declares its use of LayoutBuilderUX
- lb_ux.module in ./
lb_ux.module - Contains lb_ux.module.
File
- src/
Element/ LayoutBuilderUX.php, line 13
Namespace
Drupal\lb_ux\ElementView source
class LayoutBuilderUX extends LayoutBuilder {
/**
* {@inheritdoc}
*/
protected function buildAdministrativeSection(SectionStorageInterface $section_storage, $delta) {
$build = parent::buildAdministrativeSection($section_storage, $delta);
$section_label = $build['#attributes']['aria-label'];
$build['configure']['#title'] = $this
->t('<span class="visually-hidden">Configure @section</span>', [
'@section' => $section_label,
]);
$build['configure']['#url'] = Url::fromRoute('layout_builder.configure_section_form', $build['configure']['#url']
->getRouteParameters());
$build['remove']['#title'] = $this
->t('<span class="visually-hidden">Remove @section</span>', [
'@section' => $section_label,
]);
$build['actions'] = [
'#type' => 'container',
'#weight' => -100,
'#attributes' => [
'class' => [
'layout-builder__actions',
'layout-builder__actions__section',
],
],
'label' => [
'#type' => 'html_tag',
'#tag' => 'span',
'#attributes' => [
'class' => [
'layout-builder__section-label',
],
],
'content' => [
'#markup' => $section_label,
],
],
'configure' => $build['configure'],
'remove' => $build['remove'],
];
unset($build['configure'], $build['remove'], $build['section_label']);
foreach (Element::children($build['layout-builder__section']) as $region) {
foreach (Element::children($build['layout-builder__section'][$region]) as $uuid) {
if (in_array($uuid, [
'layout_builder_add_block',
'region_label',
])) {
continue 1;
}
$preview_fallback_string = $build['layout-builder__section'][$region][$uuid]['#attributes']['data-layout-content-preview-placeholder-label'];
$route_parameters = $build['layout-builder__section'][$region][$uuid]['#contextual_links']['layout_builder_block']['route_parameters'];
// Remove default contextual links.
unset($build['layout-builder__section'][$region][$uuid]['#contextual_links']['layout_builder_block']);
// Ensure the 'content' key is present, as set by
// \Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray.
assert(isset($build['layout-builder__section'][$region][$uuid]['content']));
// Replace content with actions and previous content.
$build['layout-builder__section'][$region][$uuid]['content'] = [
'actions' => [
'#type' => 'container',
'#attributes' => [
'class' => [
'layout-builder__actions',
'layout-builder__actions__block',
],
'tabindex' => 0,
],
'label' => [
'#type' => 'html_tag',
'#tag' => 'span',
'#attributes' => [
'class' => [
'layout-builder__block-label',
],
],
'content' => [
'#markup' => $preview_fallback_string,
],
],
'move' => [
'#type' => 'link',
'#title' => $this
->t('<span class="visually-hidden">Move @block</span>', [
'@block' => $preview_fallback_string,
]),
'#url' => Url::fromRoute('layout_builder.move_block_form', $route_parameters),
'#attributes' => [
'class' => [
'use-ajax',
'layout-builder__link',
'layout-builder__link--move',
],
'data-dialog-type' => 'dialog',
'data-dialog-renderer' => 'off_canvas',
],
],
'configure' => [
'#type' => 'link',
'#title' => $this
->t('<span class="visually-hidden">Configure @block</span>', [
'@block' => $preview_fallback_string,
]),
'#url' => Url::fromRoute('layout_builder.update_block', $route_parameters),
'#attributes' => [
'class' => [
'use-ajax',
'layout-builder__link',
'layout-builder__link--configure',
],
'data-dialog-type' => 'dialog',
'data-dialog-renderer' => 'off_canvas',
],
],
'remove' => [
'#type' => 'link',
'#title' => $this
->t('<span class="visually-hidden">Remove @block</span>', [
'@block' => $preview_fallback_string,
]),
'#url' => Url::fromRoute('layout_builder.remove_block', $route_parameters),
'#attributes' => [
'class' => [
'use-ajax',
'layout-builder__link',
'layout-builder__link--remove',
],
'data-dialog-type' => 'dialog',
'data-dialog-renderer' => 'off_canvas',
],
],
],
'content' => $build['layout-builder__section'][$region][$uuid]['content'],
];
}
}
return $build;
}
/**
* {@inheritdoc}
*/
protected function layout(SectionStorageInterface $section_storage) {
$build = parent::layout($section_storage);
$build['#attached']['library'][] = 'lb_ux/drupal.lb_ux';
$build['#attached']['library'][] = 'lb_ux/drupal.lb_ux_message';
return $build;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AjaxHelperTrait:: |
protected | function | Gets the wrapper format of the current request. | |
AjaxHelperTrait:: |
protected | function | Determines if the current request is via AJAX. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
LayoutBuilder:: |
protected | property | The layout tempstore repository. | |
LayoutBuilder:: |
protected | property |
The messenger service. Overrides MessengerTrait:: |
|
LayoutBuilder:: |
protected | function | Builds a link to add a new section at a given delta. | |
LayoutBuilder:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
LayoutBuilder:: |
public | function |
Returns the element properties for this element. Overrides ElementInterface:: |
|
LayoutBuilder:: |
protected | function | Prepares a layout for use in the UI. | |
LayoutBuilder:: |
public | function | Pre-render callback: Renders the Layout Builder UI. | |
LayoutBuilder:: |
public | function |
Constructs a new LayoutBuilder. Overrides PluginBase:: |
|
LayoutBuilderContextTrait:: |
protected | property | The context repository. | |
LayoutBuilderContextTrait:: |
protected | function | Gets the context repository service. | |
LayoutBuilderContextTrait:: |
protected | function | Provides all available contexts, both global and section_storage-specific. | |
LayoutBuilderHighlightTrait:: |
protected | function | Provides the ID used to highlight the active Layout Builder UI element. | |
LayoutBuilderHighlightTrait:: |
protected | function | Provides the ID used to highlight the active Layout Builder UI element. | |
LayoutBuilderHighlightTrait:: |
protected | function | Provides the ID used to highlight the active Layout Builder UI element. | |
LayoutBuilderHighlightTrait:: |
protected | function | Provides the ID used to highlight the active Layout Builder UI element. | |
LayoutBuilderUX:: |
protected | function |
Builds the render array for the layout section while editing. Overrides LayoutBuilder:: |
|
LayoutBuilderUX:: |
protected | function |
Renders the Layout UI. Overrides LayoutBuilder:: |
|
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
RenderElement:: |
public static | function | Adds Ajax information about an element to communicate with JavaScript. | |
RenderElement:: |
public static | function | Adds members of this group as actual elements for rendering. | |
RenderElement:: |
public static | function | Form element processing handler for the #ajax form property. | 1 |
RenderElement:: |
public static | function | Arranges elements into groups. | |
RenderElement:: |
public static | function |
Sets a form element's class attribute. Overrides ElementInterface:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |