class PurgeConfigurationsConfirmForm in Easy Install 8.9
Same name and namespace in other branches
- 8.10 src/Form/PurgeConfigurationsConfirmForm.php \Drupal\easy_install\Form\PurgeConfigurationsConfirmForm
- 8.5 src/Form/PurgeConfigurationsConfirmForm.php \Drupal\easy_install\Form\PurgeConfigurationsConfirmForm
- 8.6 src/Form/PurgeConfigurationsConfirmForm.php \Drupal\easy_install\Form\PurgeConfigurationsConfirmForm
- 8.7 src/Form/PurgeConfigurationsConfirmForm.php \Drupal\easy_install\Form\PurgeConfigurationsConfirmForm
- 8.8 src/Form/PurgeConfigurationsConfirmForm.php \Drupal\easy_install\Form\PurgeConfigurationsConfirmForm
Builds a confirmation form to uninstall selected modules.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfirmFormBase implements ConfirmFormInterface
- class \Drupal\easy_install\Form\PurgeConfigurationsConfirmForm uses ConfigDependencyDeleteFormTrait
- class \Drupal\Core\Form\ConfirmFormBase implements ConfirmFormInterface
Expanded class hierarchy of PurgeConfigurationsConfirmForm
1 string reference to 'PurgeConfigurationsConfirmForm'
File
- src/
Form/ PurgeConfigurationsConfirmForm.php, line 19
Namespace
Drupal\easy_install\FormView source
class PurgeConfigurationsConfirmForm extends ConfirmFormBase {
use ConfigDependencyDeleteFormTrait;
/**
* The module installer service.
*
* @var \Drupal\Core\Extension\ModuleInstallerInterface
*/
protected $moduleInstaller;
/**
* The expirable key value store.
*
* @var \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface
*/
protected $keyValueExpirable;
/**
* The configuration manager.
*
* @var \Drupal\Core\Config\ConfigManagerInterface
*/
protected $configManager;
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
/**
* An array of modules to uninstall.
*
* @var array
*/
protected $modules = [];
/**
* Constructs a ModulesUninstallConfirmForm object.
*
* @param \Drupal\Core\Extension\ModuleInstallerInterface $module_installer
* The module installer.
* @param \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface $key_value_expirable
* The key value expirable factory.
* @param \Drupal\Core\Config\ConfigManagerInterface $config_manager
* The configuration manager.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
*/
public function __construct(ModuleInstallerInterface $module_installer, KeyValueStoreExpirableInterface $key_value_expirable, ConfigManagerInterface $config_manager, EntityManagerInterface $entity_manager) {
$this->moduleInstaller = $module_installer;
$this->keyValueExpirable = $key_value_expirable;
$this->configManager = $config_manager;
$this->entityManager = $entity_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('module_installer'), $container
->get('keyvalue.expirable')
->get('easy_install_purgeconfigs'), $container
->get('config.manager'), $container
->get('entity.manager'));
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this
->t('Confirm Purge Configurations');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this
->t('Purge Configurations');
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
return new Url('easy_install.purge_configurations');
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return $this
->t('Would you like to continue with purge the above?');
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'purge_configuration_confirm_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
// Retrieve the list of modules from the key value store.
$account = $this
->currentUser()
->id();
$this->modules = $this->keyValueExpirable
->get($account);
// Prevent this page from showing when the module list is empty.
if (empty($this->modules['install'])) {
drupal_set_message($this
->t('The selected modules could not be Purged, either due to a website problem or due to the uninstall confirmation form timing out. Please try again.'), 'error');
return $this
->redirect('easy_install.purge_configurations');
}
$form['text']['#markup'] = '<p>' . $this
->t('Select the following configurations, selected configs will be completely deleted from your site!') . '</p>';
$form['modules'] = [
'#theme' => 'item_list',
'#items' => $this->modules['install'],
];
foreach ($this->modules['install'] as $module => $module_name) {
$install_dir = drupal_get_path('module', $module) . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY;
$optional_dir = drupal_get_path('module', $module) . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY;
$install_details = file_scan_directory($install_dir, "/\\.(yml)\$/");
if (!empty($install_details)) {
$form['modules_config'][$module] = [
'#type' => 'details',
'#title' => t('@name', [
'@name' => $module,
]),
'#description' => t('We found that @description module have configurations with it, if you like to delete it Please select the checkbox', [
'@description' => $module,
]),
'#weight' => 0,
'#validated' => TRUE,
'#open' => TRUE,
];
$install_details = file_scan_directory($install_dir, "/\\.(yml)\$/");
$ins_options = [];
foreach ($install_details as $config_value) {
$ins_options[$config_value->name] = $config_value->name;
}
if (!empty($ins_options)) {
$form['modules_config'][$module]['configs'] = [
'#type' => 'checkboxes',
'#label' => $config_value->name,
'#title' => 'Select the configurations to be deleted',
'#options' => $ins_options,
'#validated' => TRUE,
];
}
$optional_details = file_scan_directory($optional_dir, "/\\.(yml)\$/");
$opt_options = [];
foreach ($optional_details as $config_value) {
$opt_options[$config_value->name] = $config_value->name;
}
if (!empty($opt_options)) {
$form['modules_config'][$module]['opt_details'] = [
'#type' => 'details',
'#title' => "Optional Configurations",
'#weight' => 0,
'#validated' => TRUE,
'#open' => TRUE,
];
$form['modules_config'][$module]['opt_details']['opt_configs'] = [
'#type' => 'checkboxes',
'#label' => $config_value->name,
'#options' => $opt_options,
'#validated' => TRUE,
];
}
}
}
$label = 'Delete all the listed configurations except optional';
if (empty($opt_options)) {
$label = 'Delete all the listed configurations';
}
if (!empty($ins_options)) {
$form['ins_all_configs'] = [
'#type' => 'checkbox',
'#label' => $label,
'#title' => $label,
'#validated' => TRUE,
];
}
if (!empty($opt_options)) {
$form['opt_all_configs'] = [
'#type' => 'checkbox',
'#label' => 'Delete all the listed Optional configurations',
'#title' => 'Delete all the listed Optional configurations',
'#validated' => TRUE,
];
}
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Clear the key value store entry.
$account = $this
->currentUser()
->id();
$ins_configs = $form_state
->getValue('configs') ? $form_state
->getValue('configs') : [];
if ($form_state
->getValue('ins_all_configs') != 0) {
foreach ($ins_configs as $key => $value) {
\Drupal::configFactory()
->getEditable($key)
->delete();
}
}
else {
foreach ($ins_configs as $key => $values) {
if ($values !== 0) {
\Drupal::configFactory()
->getEditable($key)
->delete();
}
}
}
$opt_configs = $form_state
->getValue('opt_configs') ? $form_state
->getValue('opt_configs') : [];
if ($form_state
->getValue('opt_all_configs') != 0) {
foreach ($opt_configs as $key => $value) {
\Drupal::configFactory()
->getEditable($key)
->delete();
}
$msg = 'The selected modules have been uninstalled and configurations
deleted';
}
else {
foreach ($opt_configs as $key => $values) {
if ($values !== 0) {
\Drupal::configFactory()
->getEditable($key)
->delete();
$msg = 'The selected modules have been uninstalled and configurations
deleted';
}
}
}
$this->keyValueExpirable
->delete($account);
drupal_set_message($this
->t('The selected configurations have
been deleted.'));
$form_state
->setRedirectUrl($this
->getCancelUrl());
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigDependencyDeleteFormTrait:: |
protected | function | Adds form elements to list affected configuration entities. | |
ConfigDependencyDeleteFormTrait:: |
abstract protected | function | Translates a string to the current language or to a given language. | |
ConfirmFormBase:: |
public | function |
Returns a caption for the link which cancels the action. Overrides ConfirmFormInterface:: |
1 |
ConfirmFormBase:: |
public | function |
Returns the internal name used to refer to the confirmation item. Overrides ConfirmFormInterface:: |
|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PurgeConfigurationsConfirmForm:: |
protected | property | The configuration manager. | |
PurgeConfigurationsConfirmForm:: |
protected | property | The entity manager. | |
PurgeConfigurationsConfirmForm:: |
protected | property | The expirable key value store. | |
PurgeConfigurationsConfirmForm:: |
protected | property | The module installer service. | |
PurgeConfigurationsConfirmForm:: |
protected | property | An array of modules to uninstall. | |
PurgeConfigurationsConfirmForm:: |
public | function |
Form constructor. Overrides ConfirmFormBase:: |
|
PurgeConfigurationsConfirmForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
PurgeConfigurationsConfirmForm:: |
public | function |
Returns the route to go to if the user cancels the action. Overrides ConfirmFormInterface:: |
|
PurgeConfigurationsConfirmForm:: |
public | function |
Returns a caption for the button that confirms the action. Overrides ConfirmFormBase:: |
|
PurgeConfigurationsConfirmForm:: |
public | function |
Returns additional text to display as a description. Overrides ConfirmFormBase:: |
|
PurgeConfigurationsConfirmForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
PurgeConfigurationsConfirmForm:: |
public | function |
Returns the question to ask the user. Overrides ConfirmFormInterface:: |
|
PurgeConfigurationsConfirmForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
PurgeConfigurationsConfirmForm:: |
public | function | Constructs a ModulesUninstallConfirmForm object. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |