Commit 7361d56b authored by Dries's avatar Dries

Issue #1946454 by andypost, kim.pepper, tim.plunkett, ParisLiakos: Convert all...

Issue #1946454 by andypost, kim.pepper, tim.plunkett, ParisLiakos: Convert all confirm_form() in system.module and system.admin.inc to the new form interface and convert route.
parent 2dfd1fcc
<?php
/**
* @file
* Contains \Drupal\system\Form\DateFormatDeleteForm.
*/
namespace Drupal\system\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\ControllerInterface;
use Drupal\Core\Config\ConfigFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Builds a form to delete a date format.
*/
class DateFormatDeleteForm extends ConfirmFormBase implements ControllerInterface {
/**
* The date format data to be deleted.
*
* @var array
*/
protected $format;
/**
* The ID of the date format to be deleted.
*
* @var string
*/
protected $formatID;
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactory
*/
protected $configFactory;
/**
* Constructs a DateFormatDeleteForm object.
*/
public function __construct(ConfigFactory $config_factory) {
$this->configFactory = $config_factory;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory')
);
}
/**
* {@inheritdoc}
*/
public function getFormID() {
return 'system_date_delete_format_form';
}
/**
* {@inheritdoc}
*/
protected function getQuestion() {
return t('Are you sure you want to remove the format %name : %format?', array(
'%name' => $this->format['name'],
'%format' => format_date(REQUEST_TIME, $this->formatID))
);
}
/**
* {@inheritdoc}
*/
protected function getConfirmText() {
return t('Remove');
}
/**
* {@inheritdoc}
*/
protected function getCancelPath() {
return 'admin/config/regional/date-time/formats';
}
/**
* {@inheritdoc}
*
* @param string $format_id
* The date format ID.
*/
public function buildForm(array $form, array &$form_state, $format_id = NULL) {
// We don't get the format ID in the returned format array.
$this->formatID = $format_id;
$this->format = $this->configFactory->get('system.date')->get("formats.$format_id");
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
system_date_format_delete($this->formatID);
drupal_set_message(t('Removed date format %format.', array('%format' => $this->format['name'])));
$form_state['redirect'] = 'admin/config/regional/date-time/formats';
}
}
<?php
/**
* @file
* Contains \Drupal\system\Form\DateFormatLocalizeResetForm.
*/
namespace Drupal\system\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\ControllerInterface;
use Drupal\Core\Config\ConfigFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Builds a form for enabling a module.
*/
class DateFormatLocalizeResetForm extends ConfirmFormBase implements ControllerInterface {
/**
* The language to be reset.
*
* @var \Drupal\Core\Language\Language;
*/
protected $language;
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactory
*/
protected $configFactory;
/**
* Constructs a DateFormatLocalizeResetForm object.
*/
public function __construct(ConfigFactory $config_factory) {
$this->configFactory = $config_factory;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory')
);
}
/**
* {@inheritdoc}
*/
public function getFormID() {
return 'system_date_format_localize_reset_form';
}
/**
* {@inheritdoc}
*/
protected function getQuestion() {
return t('Are you sure you want to reset the date formats for %language to the global defaults?', array(
'%language' => $this->language->name,
));
}
/**
* {@inheritdoc}
*/
protected function getConfirmText() {
return t('Reset');
}
/**
* {@inheritdoc}
*/
protected function getCancelPath() {
return 'admin/config/regional/date-time/locale';
}
/**
* {@inheritdoc}
*/
protected function getDescription() {
return t('Resetting will remove all localized date formats for this language. This action cannot be undone.');
}
/**
* {@inheritdoc}
*
* @param string $langcode
* The language code.
*
*/
public function buildForm(array $form, array &$form_state, $langcode = NULL) {
$this->language = language_load($langcode);
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$this->configFactory->get('locale.config.' . $this->language->langcode . '.system.date')->delete();
$form_state['redirect'] = 'admin/config/regional/date-time/locale';
}
}
<?php
/**
* @file
* Contains \Drupal\system\Form\ModulesInstallConfirmForm.
*/
namespace Drupal\system\Form;
use Drupal\Core\Form\ConfirmFormBase;
/**
* Builds a confirmation form for required modules.
*
* Used internally in system_modules().
*/
class ModulesInstallConfirmForm extends ConfirmFormBase {
/**
* {@inheritdoc}
*/
protected function getQuestion() {
return t('Some required modules must be enabled');
}
/**
* {@inheritdoc}
*/
protected function getConfirmText() {
return t('Continue');
}
/**
* {@inheritdoc}
*/
protected function getCancelPath() {
return 'admin/modules';
}
/**
* {@inheritdoc}
*/
protected function getDescription() {
return t('Would you like to continue with the above?');
}
/**
* {@inheritdoc}
*/
public function getFormID() {
return 'system_modules_confirm_form';
}
/**
* {@inheritdoc}
* @param array $modules
* The array of modules.
* @param array $storage
* Temporary storage of module dependency information.
*/
public function buildForm(array $form, array &$form_state, $modules = array(), $storage = array()) {
$items = array();
$form['validation_modules'] = array('#type' => 'value', '#value' => $modules);
$form['status']['#tree'] = TRUE;
foreach ($storage['more_required'] as $info) {
$t_argument = array(
'@module' => $info['name'],
'@required' => implode(', ', $info['requires']),
);
$items[] = format_plural(count($info['requires']), 'You must enable the @required module to install @module.', 'You must enable the @required modules to install @module.', $t_argument);
}
foreach ($storage['missing_modules'] as $name => $info) {
$t_argument = array(
'@module' => $name,
'@depends' => implode(', ', $info['depends']),
);
$items[] = format_plural(count($info['depends']), 'The @module module is missing, so the following module will be disabled: @depends.', 'The @module module is missing, so the following modules will be disabled: @depends.', $t_argument);
}
$form['modules'] = array('#theme' => 'item_list', '#items' => $items);
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
}
}
<?php
/**
* @file
* Contains \Drupal\system\Form\ModulesUninstallConfirmForm.
*/
namespace Drupal\system\Form;
use Drupal\Core\Form\ConfirmFormBase;
/**
* Builds a confirmation form to uninstall selected modules.
*
* Used internally from system_modules_uninstall().
*/
class ModulesUninstallConfirmForm extends ConfirmFormBase {
/**
* {@inheritdoc}
*/
protected function getQuestion() {
return t('Confirm uninstall');
}
/**
* {@inheritdoc}
*/
protected function getConfirmText() {
return t('Uninstall');
}
/**
* {@inheritdoc}
*/
protected function getCancelPath() {
return 'admin/modules/uninstall';
}
/**
* {@inheritdoc}
*/
protected function getDescription() {
return t('Would you like to continue with uninstalling the above?');
}
/**
* {@inheritdoc}
*/
public function getFormID() {
return 'system_modules_uninstall_confirm_form';
}
/**
* {@inheritdoc}
*
* @param array $modules
* The array of modules.
*/
public function buildForm(array $form, array &$form_state, $modules = array()) {
$uninstall = array();
// Construct the hidden form elements and list items.
foreach ($modules as $module => $value) {
$info = drupal_parse_info_file(drupal_get_path('module', $module) . '/' . $module . '.info.yml');
$uninstall[] = $info['name'];
$form['uninstall'][$module] = array('#type' => 'hidden', '#value' => 1);
}
$form['#confirmed'] = TRUE;
$form['uninstall']['#tree'] = TRUE;
$form['text'] = array('#markup' => '<p>' . 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' => $uninstall);
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
}
}
......@@ -11,6 +11,8 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\system\Form\ModulesInstallConfirmForm;
use Drupal\system\Form\ModulesUninstallConfirmForm;
/**
* Menu callback; Provide the administration overview page.
......@@ -789,7 +791,7 @@ function _system_is_incompatible(&$incompatible, $files, $file) {
}
/**
* Menu callback; provides module enable/disable interface.
* Form constructor for the module enable/disable interface.
*
* The list of modules gets populated by module.info.yml files, which contain
* each module's name, description, and information about which modules it
......@@ -800,15 +802,11 @@ function _system_is_incompatible(&$incompatible, $files, $file) {
* - can not be enabled if there are disabled modules it requires.
* - can not be disabled if there are enabled modules which depend on it.
*
* @param $form_state
* An associative array containing the current state of the form.
*
* @return
* The form array.
*
* @ingroup forms
* @see system_menu()
* @see theme_system_modules()
* @see system_modules_submit()
*
* @ingroup forms
*/
function system_modules($form, $form_state = array()) {
// Get current list of modules.
......@@ -829,7 +827,10 @@ function system_modules($form, $form_state = array()) {
// filled, triggering a rebuild. In this case we need to display a
// confirmation form.
if (!empty($form_state['storage'])) {
return system_modules_confirm_form($visible_files, $form_state['storage']);
// Contents of confirm form is injected here because already in form
// building function.
$confirm_form = new ModulesInstallConfirmForm();
return $confirm_form->buildForm($form, $form_state, $visible_files, $form_state['storage']);
}
// JS-only table filters.
......@@ -1084,53 +1085,6 @@ function _system_modules_build_row($info, $extra) {
return $form;
}
/**
* Display confirmation form for required modules.
*
* @param $modules
* Array of module file objects as returned from system_rebuild_module_data().
* @param $storage
* The contents of $form_state['storage']; an array with two
* elements: the list of required modules and the list of status
* form field values from the previous screen.
* @ingroup forms
*/
function system_modules_confirm_form($modules, $storage) {
$items = array();
$form['validation_modules'] = array('#type' => 'value', '#value' => $modules);
$form['status']['#tree'] = TRUE;
foreach ($storage['more_required'] as $info) {
$t_argument = array(
'@module' => $info['name'],
'@required' => implode(', ', $info['requires']),
);
$items[] = format_plural(count($info['requires']), 'You must enable the @required module to install @module.', 'You must enable the @required modules to install @module.', $t_argument);
}
foreach ($storage['missing_modules'] as $name => $info) {
$t_argument = array(
'@module' => $name,
'@depends' => implode(', ', $info['depends']),
);
$items[] = format_plural(count($info['depends']), 'The @module module is missing, so the following module will be disabled: @depends.', 'The @module module is missing, so the following modules will be disabled: @depends.', $t_argument);
}
$form['modules'] = array('#theme' => 'item_list', '#items' => $items);
// Set some default form values
$form = confirm_form(
$form,
t('Some required modules must be enabled'),
'admin/modules',
t('Would you like to continue with the above?'),
t('Continue'),
t('Cancel'));
return $form;
}
/**
* Submit callback; handles modules form submission.
*/
......@@ -1272,23 +1226,24 @@ function system_modules_submit($form, &$form_state) {
*/
/**
* Builds a form of currently disabled modules.
* Form constructor for the uninstalling disabled modules form.
*
* @ingroup forms
* @see system_menu()
* @see system_modules_uninstall_validate()
* @see system_modules_uninstall_submit()
* @param $form_state['values']
* Submitted form values.
* @return
* A form array representing the currently disabled modules.
*
* @ingroup forms
*/
function system_modules_uninstall($form, $form_state = NULL) {
// Make sure the install API is available.
include_once DRUPAL_ROOT . '/core/includes/install.inc';
// Display the confirm form if any modules have been submitted.
if (!empty($form_state['storage']) && $confirm_form = system_modules_uninstall_confirm_form($form_state['storage'])) {
return $confirm_form;
if (!empty($form_state['storage']['uninstall']) && $modules = array_filter($form_state['storage']['uninstall'])) {
// Contents of confirm form is injected here because already in form
// building function.
$confirm_form = new ModulesUninstallConfirmForm();
return $confirm_form->buildForm($form, $form_state, $modules);
}
// Get a list of disabled, installed modules.
......@@ -1341,47 +1296,6 @@ function system_modules_uninstall($form, $form_state = NULL) {
return $form;
}
/**
* Confirm uninstall of selected modules.
*
* @ingroup forms
* @param $storage
* An associative array of modules selected to be uninstalled.
* @return
* A form array representing modules to confirm.
*/
function system_modules_uninstall_confirm_form($storage) {
// Nothing to build.
if (empty($storage)) {
return;
}
// Construct the hidden form elements and list items.
foreach (array_filter($storage['uninstall']) as $module => $value) {
$info = drupal_parse_info_file(drupal_get_path('module', $module) . '/' . $module . '.info.yml');
$uninstall[] = $info['name'];
$form['uninstall'][$module] = array('#type' => 'hidden',
'#value' => 1,
);
}
// Display a confirm form if modules have been selected.
if (isset($uninstall)) {
$form['#confirmed'] = TRUE;
$form['uninstall']['#tree'] = TRUE;
$form['text'] = array('#markup' => '<p>' . 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' => $uninstall);
$form = confirm_form(
$form,
t('Confirm uninstall'),
'admin/modules/uninstall',
t('Would you like to continue with uninstalling the above?'),
t('Uninstall'),
t('Cancel'));
return $form;
}
}
/**
* Validates the submitted uninstall form.
*/
......@@ -1916,41 +1830,6 @@ function theme_system_themes_page($variables) {
return $output;
}
/**
* Menu callback; present a form for deleting a date format.
*
* @param string $date_format_id
* The machine name for the date format that may be deleted.
*/
function system_date_delete_format_form($form, &$form_state, $date_format_id) {
$form['date_format_id'] = array(
'#type' => 'value',
'#value' => $date_format_id,
);
$format = system_get_date_formats($date_format_id);
$output = confirm_form($form,
t('Are you sure you want to remove the format %name : %format?', array('%name' => $format['name'], '%format' => format_date(REQUEST_TIME, $date_format_id))),
'admin/config/regional/date-time/formats',
t('This action cannot be undone.'),
t('Remove'), t('Cancel'),
'confirm'
);
return $output;
}
/**
* Delete a configured date format.
*/
function system_date_delete_format_form_submit($form, &$form_state) {
if ($form_state['values']['confirm']) {
$format = system_get_date_formats($form_state['values']['date_format_id']);
system_date_format_delete($form_state['values']['date_format_id']);
drupal_set_message(t('Removed date format %format.', array('%format' => $format['name'])));
$form_state['redirect'] = 'admin/config/regional/date-time/formats';
}
}
/**
* Displays the date format strings overview page.
*/
......@@ -2302,34 +2181,6 @@ function theme_system_date_format_localize_form($variables) {
return $output;
}
/**
* Form constructor for the reset date format form.
*
* @param $langcode
* Language code, e.g. 'en'.
*
* @see locale_menu()
* @see system_date_format_localize_reset_form_submit()
* @ingroup forms
*/
function system_date_format_localize_reset_form($form, &$form_state, $langcode) {
$form['langcode'] = array('#type' => 'value', '#value' => $langcode);
return confirm_form($form,
t('Are you sure you want to reset the date formats for %language to the global defaults?', array('%language' => language_load($langcode)->name)),
'admin/config/regional/date-time/locale',
t('Resetting will remove all localized date formats for this language. This action cannot be undone.'),
t('Reset'), t('Cancel'));
}
/**
* Form submission handler for locale_date_format_reset_form().
*/
function system_date_format_localize_reset_form_submit($form, &$form_state) {
config('locale.config.' . $form['langcode']['#value'] . '.system.date')
->delete();
$form_state['redirect'] = 'admin/config/regional/date-time/locale';
}
/**
* Save locale specific date formats to the database.
*
......
</
......@@ -906,10 +906,7 @@ function system_menu() {
$items['admin/config/regional/date-time/formats/%system_date_format/delete'] = array(
'title' => 'Delete date format',
'description' => 'Allow users to delete a configured date format.',
'page callback' => 'drupal_get_form',
'page arguments' => array('system_date_delete_format_form', 5),
'access arguments' => array('administer site configuration'),
'file' => 'system.admin.inc',
'route_name' => 'date_format_delete',
);
$items['admin/config/regional/date-time/formats/lookup'] = array(