You are here

public function ConfigDeleteForm::submitForm in Config Delete 8

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

File

src/Form/ConfigDeleteForm.php, line 36

Class

ConfigDeleteForm
Provides a form for deleting a single configuration file.

Namespace

Drupal\config_delete\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $config_type = $form_state
    ->getValue('config_type');
  $config_name = $form_state
    ->getValue('config_name');
  if ($form_state
    ->getValue('config_type') !== 'system.simple') {
    $definition = $this->entityTypeManager
      ->getDefinition($config_type);
    $name = $definition
      ->getConfigPrefix() . '.' . $config_name;
  }
  else {
    $name = $config_name;
  }
  $message = $this
    ->t('Configuration "@config_name" successfully deleted.', [
    '@config_name' => $name,
  ]);
  if ($form_state
    ->getValue('delete_dependencies')) {
    $dependencies = \Drupal::configFactory()
      ->get($name)
      ->get('dependencies');
    if (isset($dependencies['config'])) {
      foreach ($dependencies['config'] as $config_name) {
        $this
          ->deleteConfig($config_name);
      }
      $message = $this
        ->t('Configuration "@config_name" and all its dependencies successfully deleted.', [
        '@config_name' => $name,
      ]);
    }
  }
  $this
    ->deleteConfig($name);
  \Drupal::messenger()
    ->addStatus($message);
}