ModulesUninstallConfirmForm.php in Zircon Profile 8
File
core/modules/system/src/Form/ModulesUninstallConfirmForm.php
View source
<?php
namespace Drupal\system\Form;
use Drupal\Core\Config\ConfigManagerInterface;
use Drupal\Core\Config\Entity\ConfigDependencyDeleteFormTrait;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Extension\ModuleInstallerInterface;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface;
class ModulesUninstallConfirmForm extends ConfirmFormBase {
use ConfigDependencyDeleteFormTrait;
protected $moduleInstaller;
protected $keyValueExpirable;
protected $configManager;
protected $entityManager;
protected $modules = array();
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;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('module_installer'), $container
->get('keyvalue.expirable')
->get('modules_uninstall'), $container
->get('config.manager'), $container
->get('entity.manager'));
}
public function getQuestion() {
return $this
->t('Confirm uninstall');
}
public function getConfirmText() {
return $this
->t('Uninstall');
}
public function getCancelUrl() {
return new Url('system.modules_uninstall');
}
public function getDescription() {
return $this
->t('Would you like to continue with uninstalling the above?');
}
public function getFormId() {
return 'system_modules_uninstall_confirm_form';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$account = $this
->currentUser()
->id();
$this->modules = $this->keyValueExpirable
->get($account);
if (empty($this->modules)) {
drupal_set_message($this
->t('The selected modules could not be uninstalled, either due to a website problem or due to the uninstall confirmation form timing out. Please try again.'), 'error');
return $this
->redirect('system.modules_uninstall');
}
$data = system_rebuild_module_data();
$form['text']['#markup'] = '<p>' . $this
->t('The following modules will be completely uninstalled from your site, and <em>all data from these modules will be lost</em>!') . '</p>';
$form['modules'] = array(
'#theme' => 'item_list',
'#items' => array_map(function ($module) use ($data) {
return $data[$module]->info['name'];
}, $this->modules),
);
$this
->addDependencyListsToForm($form, 'module', $this->modules, $this->configManager, $this->entityManager);
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$account = $this
->currentUser()
->id();
$this->keyValueExpirable
->delete($account);
$this->moduleInstaller
->uninstall($this->modules);
drupal_set_message($this
->t('The selected modules have been uninstalled.'));
$form_state
->setRedirectUrl($this
->getCancelUrl());
}
}