You are here

public function LayoutBuilderForm::buildForm in Page Manager 8.4

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

src/Form/LayoutBuilderForm.php, line 88

Class

LayoutBuilderForm
Provides a form containing the Layout Builder UI for Page Manager.

Namespace

Drupal\page_manager\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $cached_values = $form_state
    ->getTemporaryValue('wizard');

  /** @var \Drupal\page_manager\PageVariantInterface $page_variant */
  $page_variant = $cached_values['page_variant'];

  // If this is a new variant, put it in the tempstore so that we can
  // retrieve it by id later.
  // @see \Drupal\page_manager\Plugin\SectionStorage\PageManagerSectionStorage::deriveContextsFromRoute.
  if ($page_variant
    ->isNew()) {
    $this->tempstore
      ->get('page_manager.layout_builder')
      ->set($page_variant
      ->id(), $page_variant);
  }
  $section_storage = $this->sectionStorageManager
    ->load('page_manager', [
    'entity' => EntityContext::fromEntity($page_variant),
  ]);
  $this->sectionStorage = $this->layoutTempstoreRepository
    ->get($section_storage);
  $form['preview_toggle'] = $this
    ->buildContentPreviewToggle();
  $form['layout_builder'] = [
    '#type' => 'layout_builder',
    '#section_storage' => $this->sectionStorage,
  ];
  return $form;
}