You are here

public function LayoutBuilderUpdateBlockForm::submitForm in Panopoly Magic 8.2

Form submission handler.

Parameters

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

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

Overrides ConfigureBlockFormBase::submitForm

File

src/Form/LayoutBuilderUpdateBlockForm.php, line 77

Class

LayoutBuilderUpdateBlockForm
Enhances the update block form with live preview.

Namespace

Drupal\panopoly_magic\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // Handle preview mode.
  if ($form_state
    ->getValue('op') == $form['actions']['preview']['#value']) {

    // Call the plugin submit handler.
    $subform_state = SubformState::createForSubform($form['settings'], $form, $form_state);
    $this
      ->getPluginForm($this->block)
      ->submitConfigurationForm($form, $subform_state);

    // Update the component configuration.
    $configuration = array_merge($this->block
      ->getConfiguration(), $form_state
      ->getValue('settings'));
    $section = $this->sectionStorage
      ->getSection($this->delta);
    $section
      ->getComponent($this->uuid)
      ->setConfiguration($configuration);

    // We want to preview so rebuild the layout only.
    // Do not update the temp layout storage.
    // Preview config can hence be discarded and are not saved.
    return $this
      ->rebuildLayout($this->sectionStorage);
  }
  elseif ($form_state
    ->getValue('op') == $form['actions']['cancel']['#value']) {

    // Pull the last configuration from the temp layout storage and rebuild
    // the layout.
    $this->sectionStorage = $this->layoutTempstoreRepository
      ->get($this->sectionStorage);
    return $this
      ->rebuildLayout($this->sectionStorage);
  }
  parent::submitForm($form, $form_state);
}