You are here

public function ConfigPagesClearConfirmationForm::submitForm in Config Pages 8.2

Same name and namespace in other branches
  1. 8.3 src/Form/ConfigPagesClearConfirmationForm.php \Drupal\config_pages\Form\ConfigPagesClearConfirmationForm::submitForm()
  2. 8 src/Form/ConfigPagesClearConfirmationForm.php \Drupal\config_pages\Form\ConfigPagesClearConfirmationForm::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

src/Form/ConfigPagesClearConfirmationForm.php, line 71

Class

ConfigPagesClearConfirmationForm
Action on clear ConfigPage submit form.

Namespace

Drupal\config_pages\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $entity_id = $this->id;
  $entity = ConfigPages::load($entity_id);
  $fields = $entity
    ->getFieldDefinitions();
  foreach ($fields as $name => $field) {

    // Process only fields added from BO.
    if ($field instanceof FieldConfigInterface) {
      $entity
        ->set($name, $field
        ->getDefaultValue($entity));
    }
  }
  $entity
    ->save();
  $form_state
    ->setRedirectUrl($entity
    ->toUrl());
}