class ModulesListConfirmForm
Same name in other branches
- 8.9.x core/modules/system/src/Form/ModulesListConfirmForm.php \Drupal\system\Form\ModulesListConfirmForm
- 10 core/modules/system/src/Form/ModulesListConfirmForm.php \Drupal\system\Form\ModulesListConfirmForm
- 11.x core/modules/system/src/Form/ModulesListConfirmForm.php \Drupal\system\Form\ModulesListConfirmForm
Builds a confirmation form for enabling modules with dependencies.
@internal
Hierarchy
- class \Drupal\Core\Form\FormBase implements \Drupal\Core\Form\FormInterface, \Drupal\Core\DependencyInjection\ContainerInjectionInterface uses \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Logger\LoggerChannelTrait, \Drupal\Core\Messenger\MessengerTrait, \Drupal\Core\Routing\RedirectDestinationTrait, \Drupal\Core\StringTranslation\StringTranslationTrait
- class \Drupal\Core\Form\ConfirmFormBase extends \Drupal\Core\Form\FormBase implements \Drupal\Core\Form\ConfirmFormInterface
- class \Drupal\system\Form\ModulesListConfirmForm extends \Drupal\Core\Form\ConfirmFormBase uses \Drupal\system\Form\ModulesEnabledTrait
- class \Drupal\Core\Form\ConfirmFormBase extends \Drupal\Core\Form\FormBase implements \Drupal\Core\Form\ConfirmFormInterface
Expanded class hierarchy of ModulesListConfirmForm
1 string reference to 'ModulesListConfirmForm'
- system.routing.yml in core/
modules/ system/ system.routing.yml - core/modules/system/system.routing.yml
File
-
core/
modules/ system/ src/ Form/ ModulesListConfirmForm.php, line 20
Namespace
Drupal\system\FormView source
class ModulesListConfirmForm extends ConfirmFormBase {
use ModulesEnabledTrait;
/**
* The module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The expirable key value store.
*
* @var \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface
*/
protected $keyValueExpirable;
/**
* An associative list of modules to enable or disable.
*
* @var array
*/
protected $modules = [];
/**
* The module installer.
*
* @var \Drupal\Core\Extension\ModuleInstallerInterface
*/
protected $moduleInstaller;
/**
* Constructs a ModulesListConfirmForm 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 static function create(ContainerInterface $container) {
return new static($container->get('module_handler'), $container->get('module_installer'), $container->get('keyvalue.expirable')
->get('module_list'));
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Some required modules must be enabled');
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
return new Url('system.modules_list');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this->t('Continue');
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return $this->t('Would you like to continue with the above?');
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'system_modules_confirm_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$account = $this->currentUser()
->id();
$this->modules = $this->keyValueExpirable
->get($account);
// Redirect to the modules list page if the key value store is empty.
if (!$this->modules) {
return $this->redirect('system.modules_list');
}
$items = $this->buildMessageList();
$form['message'] = [
'#theme' => 'item_list',
'#items' => $items,
];
return parent::buildForm($form, $form_state);
}
/**
* Builds the message list for the confirmation form.
*
* @return \Drupal\Component\Render\MarkupInterface[]
* Array of markup for the list of messages on the form.
*
* @see \Drupal\system\Form\ModulesListForm::buildModuleList()
*/
protected function buildMessageList() {
$items = [];
if (!empty($this->modules['dependencies'])) {
// Display a list of required modules that have to be installed as well
// but were not manually selected.
foreach ($this->modules['dependencies'] as $module => $dependencies) {
$items[] = $this->formatPlural(count($dependencies), 'You must enable the @required module to install @module.', 'You must enable the @required modules to install @module.', [
'@module' => $this->modules['install'][$module],
// It is safe to implode this because module names are not translated
// markup and so will not be double-escaped.
'@required' => implode(', ', $dependencies),
]);
}
}
return $items;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Remove the key value store entry.
$account = $this->currentUser()
->id();
$this->keyValueExpirable
->delete($account);
if (!empty($this->modules['install'])) {
// Don't catch the exception that this can throw for missing dependencies:
// the form doesn't allow modules with unmet dependencies, so the only way
// this can happen is if the filesystem changed between form display and
// submit, in which case the user has bigger problems.
try {
// Install the given modules.
$this->moduleInstaller
->install(array_keys($this->modules['install']));
} catch (PreExistingConfigException $e) {
$this->messenger()
->addError($this->modulesFailToEnableMessage($this->modules, $e));
return;
} catch (UnmetDependenciesException $e) {
$this->messenger()
->addError($e->getTranslatedMessage($this->getStringTranslation(), $this->modules['install'][$e->getExtension()]));
return;
}
// Unset the messenger to make sure that we'll get the service from the
// new container.
$this->messenger = NULL;
$this->messenger()
->addStatus($this->modulesEnabledConfirmationMessage($this->modules['install']));
}
$form_state->setRedirectUrl($this->getCancelUrl());
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
ConfirmFormBase::getCancelText | public | function | Overrides ConfirmFormInterface::getCancelText | 2 | |
ConfirmFormBase::getFormName | public | function | Overrides ConfirmFormInterface::getFormName | ||
DependencySerializationTrait::$_entityStorages | protected | property | |||
DependencySerializationTrait::$_serviceIds | protected | property | |||
DependencySerializationTrait::__sleep | public | function | 1 | ||
DependencySerializationTrait::__wakeup | public | function | 2 | ||
FormBase::$configFactory | protected | property | The config factory. | 3 | |
FormBase::$requestStack | protected | property | The request stack. | 1 | |
FormBase::$routeMatch | protected | property | The route match. | ||
FormBase::config | protected | function | Retrieves a configuration object. | ||
FormBase::configFactory | protected | function | Gets the config factory for this form. | 3 | |
FormBase::container | private | function | Returns the service container. | ||
FormBase::getRequest | protected | function | Gets the request object. | ||
FormBase::getRouteMatch | protected | function | Gets the route match. | ||
FormBase::logger | protected | function | Gets the logger for a specific channel. | ||
FormBase::redirect | protected | function | Returns a redirect response object for the specified route. | ||
FormBase::resetConfigFactory | public | function | Resets the configuration factory. | ||
FormBase::setConfigFactory | public | function | Sets the config factory for this form. | ||
FormBase::setRequestStack | public | function | Sets the request stack object to use. | ||
FormBase::validateForm | public | function | Overrides FormInterface::validateForm | 73 | |
LoggerChannelTrait::$loggerFactory | protected | property | The logger channel factory service. | ||
LoggerChannelTrait::getLogger | protected | function | Gets the logger for a specific channel. | ||
LoggerChannelTrait::setLoggerFactory | public | function | Injects the logger channel factory. | ||
MessengerTrait::$messenger | protected | property | The messenger. | 17 | |
MessengerTrait::messenger | public | function | Gets the messenger. | 17 | |
MessengerTrait::setMessenger | public | function | Sets the messenger. | ||
ModulesEnabledTrait::currentUser | abstract protected | function | Gets the current user. | ||
ModulesEnabledTrait::modulesEnabledConfirmationMessage | protected | function | Provides a confirmation message after modules have been enabled. | ||
ModulesEnabledTrait::modulesFailToEnableMessage | protected | function | Provides a fail message after attempt to install a module. | ||
ModulesListConfirmForm::$keyValueExpirable | protected | property | The expirable key value store. | ||
ModulesListConfirmForm::$moduleHandler | protected | property | The module handler service. | ||
ModulesListConfirmForm::$moduleInstaller | protected | property | The module installer. | ||
ModulesListConfirmForm::$modules | protected | property | An associative list of modules to enable or disable. | ||
ModulesListConfirmForm::buildForm | public | function | Overrides ConfirmFormBase::buildForm | ||
ModulesListConfirmForm::buildMessageList | protected | function | Builds the message list for the confirmation form. | 1 | |
ModulesListConfirmForm::create | public static | function | Overrides FormBase::create | 1 | |
ModulesListConfirmForm::getCancelUrl | public | function | Overrides ConfirmFormInterface::getCancelUrl | ||
ModulesListConfirmForm::getConfirmText | public | function | Overrides ConfirmFormBase::getConfirmText | ||
ModulesListConfirmForm::getDescription | public | function | Overrides ConfirmFormBase::getDescription | ||
ModulesListConfirmForm::getFormId | public | function | Overrides FormInterface::getFormId | 1 | |
ModulesListConfirmForm::getQuestion | public | function | Overrides ConfirmFormInterface::getQuestion | 1 | |
ModulesListConfirmForm::submitForm | public | function | Overrides FormInterface::submitForm | ||
ModulesListConfirmForm::__construct | public | function | Constructs a ModulesListConfirmForm object. | 1 | |
RedirectDestinationTrait::$redirectDestination | protected | property | The redirect destination service. | 1 | |
RedirectDestinationTrait::getDestinationArray | protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | ||
RedirectDestinationTrait::getRedirectDestination | protected | function | Returns the redirect destination service. | ||
RedirectDestinationTrait::setRedirectDestination | public | function | Sets the redirect destination service. | ||
StringTranslationTrait::$stringTranslation | protected | property | The string translation service. | 3 | |
StringTranslationTrait::formatPlural | protected | function | Formats a string containing a count of items. | ||
StringTranslationTrait::getNumberOfPlurals | protected | function | Returns the number of plurals supported by a given language. | ||
StringTranslationTrait::getStringTranslation | protected | function | Gets the string translation service. | ||
StringTranslationTrait::setStringTranslation | public | function | Sets the string translation service to use. | 2 | |
StringTranslationTrait::t | protected | function | Translates a string to the current language or to a given language. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.