
| Current Path : /var/www/html/rocksensor1/web/modules/contrib/config_delete/src/Form/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html/rocksensor1/web/modules/contrib/config_delete/src/Form/ConfigDeleteForm.php |
<?php
namespace Drupal\config_delete\Form;
use Drupal\config\Form\ConfigSingleExportForm;
use Drupal\Core\Form\FormStateInterface;
/**
* Provides a form for deleting a single configuration file.
*
* @internal
*/
class ConfigDeleteForm extends ConfigSingleExportForm {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'config_delete_form';
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$config_name = $form_state->getValue('config_name');
if (empty($config_name)) {
$form_state->setErrorByName('config_name', $this->t('Please select a valid configuration name.'));
}
}
/**
* {@inheritdoc}
*/
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);
}
/**
* Deletes the configuration object.
*
* @param string $name
* The configuration name.
*/
protected function deleteConfig($name) {
\Drupal::configFactory()->getEditable($name)
->delete();
}
}