You are here

public function MoveBlockForm::submitForm in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/layout_builder/src/Form/MoveBlockForm.php \Drupal\layout_builder\Form\MoveBlockForm::submitForm()

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 FormInterface::submitForm

File

core/modules/layout_builder/src/Form/MoveBlockForm.php, line 243

Class

MoveBlockForm
Provides a form for moving a block.

Namespace

Drupal\layout_builder\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $region = $this
    ->getSelectedRegion($form_state);
  $delta = $this
    ->getSelectedDelta($form_state);
  $original_section = $this->sectionStorage
    ->getSection($this->delta);
  $component = $original_section
    ->getComponent($this->uuid);
  $section = $this->sectionStorage
    ->getSection($delta);
  if ($delta !== $this->delta) {

    // Remove component from old section and add it to the new section.
    $original_section
      ->removeComponent($this->uuid);
    $section
      ->insertComponent(0, $component);
  }
  $component
    ->setRegion($region);
  foreach ($form_state
    ->getValue('components') as $uuid => $component_info) {
    $section
      ->getComponent($uuid)
      ->setWeight($component_info['weight']);
  }
  $this->layoutTempstore
    ->set($this->sectionStorage);
}