You are here

public function DeleteComponentForm::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/DeleteComponentForm.php, line 64

Class

DeleteComponentForm
Class DeleteComponentForm.

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->componentUuid = $component_uuid;
  $component = $this->layoutParagraphsLayout
    ->getComponentByUuid($this->componentUuid);
  $type = $component
    ->getEntity()
    ->getParagraphType()
    ->label();
  $form['#title'] = $this
    ->t('Delete @type', [
    '@type' => $type,
  ]);
  $form['confirm'] = [
    '#markup' => $this
      ->t('Really delete this @type? There is no undo.', [
      '@type' => $type,
    ]),
  ];
  $form['actions'] = [
    '#type' => 'actions',
    'submit' => [
      '#type' => 'submit',
      '#value' => $this
        ->t('Delete'),
      '#ajax' => [
        'callback' => '::deleteComponent',
      ],
    ],
    'cancel' => [
      '#type' => 'button',
      '#value' => $this
        ->t('Cancel'),
      '#ajax' => [
        'callback' => '::closeForm',
      ],
    ],
  ];
  return $form;
}