function ConfigDeleteForm::buildForm

Same name in other branches
  1. 4.x src/Form/ConfigDeleteForm.php \Drupal\devel\Form\ConfigDeleteForm::buildForm()

Overrides FormInterface::buildForm

File

src/Form/ConfigDeleteForm.php, line 47

Class

ConfigDeleteForm
Edit config variable form.

Namespace

Drupal\devel\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $config_name = '') : array {
    $config = $this->configFactory
        ->get($config_name);
    if ($config->isNew()) {
        $this->messenger
            ->addError($this->t('Config @name does not exist in the system.', [
            '@name' => $config_name,
        ]));
        return $form;
    }
    $form['#title'] = $this->getQuestion();
    $form['#attributes']['class'][] = 'confirmation';
    $form['description'] = [
        '#markup' => $this->getDescription(),
    ];
    $form[$this->getFormName()] = [
        '#type' => 'hidden',
        '#value' => 1,
    ];
    // By default, render the form using theme_confirm_form().
    if (!isset($form['#theme'])) {
        $form['#theme'] = 'confirm_form';
    }
    $form['name'] = [
        '#type' => 'value',
        '#value' => $config_name,
    ];
    $form['actions'] = [
        '#type' => 'actions',
    ];
    $form['actions']['submit'] = [
        '#type' => 'submit',
        '#value' => $this->getConfirmText(),
        '#submit' => [
            function (array &$form, FormStateInterface $form_state) : void {
                $this->submitForm($form, $form_state);
            },
        ],
    ];
    $form['actions']['cancel'] = ConfirmFormHelper::buildCancelLink($this, $this->requestStack
        ->getCurrentRequest());
    return $form;
}