class ModulesUninstallForm in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Form/ModulesUninstallForm.php \Drupal\system\Form\ModulesUninstallForm
Provides a form for uninstalling modules.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\system\Form\ModulesUninstallForm
Expanded class hierarchy of ModulesUninstallForm
1 string reference to 'ModulesUninstallForm'
- system.routing.yml in core/
modules/ system/ system.routing.yml - core/modules/system/system.routing.yml
File
- core/
modules/ system/ src/ Form/ ModulesUninstallForm.php, line 20 - Contains \Drupal\system\Form\ModulesUninstallForm.
Namespace
Drupal\system\FormView source
class ModulesUninstallForm extends FormBase {
/**
* The module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The module installer service.
*
* @var \Drupal\Core\Extension\ModuleInstallerInterface
*/
protected $moduleInstaller;
/**
* The expirable key value store.
*
* @var \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface
*/
protected $keyValueExpirable;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('module_handler'), $container
->get('module_installer'), $container
->get('keyvalue.expirable')
->get('modules_uninstall'));
}
/**
* Constructs a ModulesUninstallForm object.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Extension\ModuleInstallerInterface $module_installer
* The module installer.
* @param \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface $key_value_expirable
* The key value expirable factory.
*/
public function __construct(ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, KeyValueStoreExpirableInterface $key_value_expirable) {
$this->moduleHandler = $module_handler;
$this->moduleInstaller = $module_installer;
$this->keyValueExpirable = $key_value_expirable;
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'system_modules_uninstall';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
// Make sure the install API is available.
include_once DRUPAL_ROOT . '/core/includes/install.inc';
// Get a list of all available modules.
$modules = system_rebuild_module_data();
$uninstallable = array_filter($modules, function ($module) use ($modules) {
return empty($modules[$module
->getName()]->info['required']) && $module->status;
});
// Include system.admin.inc so we can use the sort callbacks.
$this->moduleHandler
->loadInclude('system', 'inc', 'system.admin');
$form['filters'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array(
'table-filter',
'js-show',
),
),
);
$form['filters']['text'] = array(
'#type' => 'search',
'#title' => $this
->t('Filter modules'),
'#title_display' => 'invisible',
'#size' => 30,
'#placeholder' => $this
->t('Filter by name or description'),
'#description' => $this
->t('Enter a part of the module name or description'),
'#attributes' => array(
'class' => array(
'table-filter-text',
),
'data-table' => '#system-modules-uninstall',
'autocomplete' => 'off',
),
);
$form['modules'] = array();
// Only build the rest of the form if there are any modules available to
// uninstall;
if (empty($uninstallable)) {
return $form;
}
$profile = drupal_get_profile();
// Sort all modules by their name.
uasort($uninstallable, 'system_sort_modules_by_info_name');
$validation_reasons = $this->moduleInstaller
->validateUninstall(array_keys($uninstallable));
$form['uninstall'] = array(
'#tree' => TRUE,
);
foreach ($uninstallable as $module_key => $module) {
$name = $module->info['name'] ?: $module
->getName();
$form['modules'][$module
->getName()]['#module_name'] = $name;
$form['modules'][$module
->getName()]['name']['#markup'] = $name;
$form['modules'][$module
->getName()]['description']['#markup'] = $this
->t($module->info['description']);
$form['uninstall'][$module
->getName()] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Uninstall @module module', array(
'@module' => $name,
)),
'#title_display' => 'invisible',
);
// If a validator returns reasons not to uninstall a module,
// list the reasons and disable the check box.
if (isset($validation_reasons[$module_key])) {
$form['modules'][$module
->getName()]['#validation_reasons'] = $validation_reasons[$module_key];
$form['uninstall'][$module
->getName()]['#disabled'] = TRUE;
}
// All modules which depend on this one must be uninstalled first, before
// we can allow this module to be uninstalled. (The installation profile
// is excluded from this list.)
foreach (array_keys($module->required_by) as $dependent) {
if ($dependent != $profile && drupal_get_installed_schema_version($dependent) != SCHEMA_UNINSTALLED) {
$name = isset($modules[$dependent]->info['name']) ? $modules[$dependent]->info['name'] : $dependent;
$form['modules'][$module
->getName()]['#required_by'][] = $name;
$form['uninstall'][$module
->getName()]['#disabled'] = TRUE;
}
}
}
$form['#attached']['library'][] = 'system/drupal.system.modules';
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => $this
->t('Uninstall'),
);
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
// Form submitted, but no modules selected.
if (!array_filter($form_state
->getValue('uninstall'))) {
$form_state
->setErrorByName('uninstall', $this
->t('No modules selected.'));
$form_state
->setRedirect('system.modules_uninstall');
}
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Save all the values in an expirable key value store.
$modules = $form_state
->getValue('uninstall');
$uninstall = array_keys(array_filter($modules));
$account = $this
->currentUser()
->id();
// Store the values for 6 hours. This expiration time is also used in
// the form cache.
$this->keyValueExpirable
->setWithExpire($account, $uninstall, 6 * 60 * 60);
// Redirect to the confirm form.
$form_state
->setRedirect('system.modules_uninstall_confirm');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | 3 |
FormBase:: |
protected | property | The logger factory. | |
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. | 3 |
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:: |
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. | |
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. | |
ModulesUninstallForm:: |
protected | property | The expirable key value store. | |
ModulesUninstallForm:: |
protected | property | The module handler service. | |
ModulesUninstallForm:: |
protected | property | The module installer service. | |
ModulesUninstallForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
ModulesUninstallForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
ModulesUninstallForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
ModulesUninstallForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
ModulesUninstallForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
ModulesUninstallForm:: |
public | function | Constructs a ModulesUninstallForm object. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | |
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. | |
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 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Returns a redirect response object for the specified route. | |
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. |