You are here

trait PreviewToggleTrait in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/layout_builder/src/Form/PreviewToggleTrait.php \Drupal\layout_builder\Form\PreviewToggleTrait
  2. 10 core/modules/layout_builder/src/Form/PreviewToggleTrait.php \Drupal\layout_builder\Form\PreviewToggleTrait

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

Hierarchy

File

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

Namespace

Drupal\layout_builder\Form
View source
trait PreviewToggleTrait {

  /**
   * Builds the content preview toggle input.
   *
   * @return array
   *   The render array for the content preview toggle.
   */
  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',
      ],
    ];
  }

  /**
   * Gets the current user.
   *
   * @return \Drupal\Core\Session\AccountInterface
   *   The current user.
   */
  protected abstract function currentUser();

}

Members

Namesort descending Modifiers Type Description Overrides
PreviewToggleTrait::buildContentPreviewToggle protected function Builds the content preview toggle input.
PreviewToggleTrait::currentUser abstract protected function Gets the current user.