You are here

public function EditComponentForm::buildForm in Layout Paragraphs 2.0.x

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/EditComponentForm.php, line 21

Class

EditComponentForm
Class LayoutParagraphsComponentEditForm.

Namespace

Drupal\layout_paragraphs\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, LayoutParagraphsLayout $layout_paragraphs_layout = NULL, string $component_uuid = NULL) {
  $this
    ->setLayoutParagraphsLayout($layout_paragraphs_layout);
  $this->paragraph = $this->layoutParagraphsLayout
    ->getComponentByUuid($component_uuid)
    ->getEntity();
  $form = $this
    ->buildComponentForm($form, $form_state);
  if ($selected_layout = $form_state
    ->getValue([
    'layout_paragraphs',
    'layout',
  ])) {
    $section = $this->layoutParagraphsLayout
      ->getLayoutSection($this->paragraph);
    if ($section && $selected_layout != $section
      ->getLayoutId()) {
      $form['layout_paragraphs']['move_items'] = [
        '#old_layout' => $section
          ->getLayoutId(),
        '#new_layout' => $selected_layout,
        '#weight' => 5,
        '#process' => [
          [
            $this,
            'orphanedItemsElement',
          ],
        ],
      ];
    }
  }
  return $form;
}