You are here

protected function PreviewToggleTrait::buildContentPreviewToggle in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/layout_builder/src/Form/PreviewToggleTrait.php \Drupal\layout_builder\Form\PreviewToggleTrait::buildContentPreviewToggle()
  2. 9 core/modules/layout_builder/src/Form/PreviewToggleTrait.php \Drupal\layout_builder\Form\PreviewToggleTrait::buildContentPreviewToggle()

Builds the content preview toggle input.

Return value

array The render array for the content preview toggle.

2 calls to PreviewToggleTrait::buildContentPreviewToggle()
DefaultsEntityForm::actions in core/modules/layout_builder/src/Form/DefaultsEntityForm.php
Returns an array of supported actions for the current entity form.
OverridesEntityForm::actions in core/modules/layout_builder/src/Form/OverridesEntityForm.php
Returns an array of supported actions for the current entity form.

File

core/modules/layout_builder/src/Form/PreviewToggleTrait.php, line 16

Class

PreviewToggleTrait
Provides a trait that provides a toggle for the content preview.

Namespace

Drupal\layout_builder\Form

Code

protected function buildContentPreviewToggle() {
  return [
    '#type' => 'container',
    '#attributes' => [
      'class' => [
        'js-show',
      ],
    ],
    'toggle_content_preview' => [
      '#title' => $this
        ->t('Show content preview'),
      '#type' => 'checkbox',
      '#value' => TRUE,
      '#attributes' => [
        // Set attribute used by local storage to get content preview status.
        'data-content-preview-id' => "Drupal.layout_builder.content_preview.{$this->currentUser()->id()}",
      ],
      '#id' => 'layout-builder-content-preview',
    ],
  ];
}