From e88f0ab7c51a89c7a88894a622722b600a0bedc6 Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org> Date: Thu, 16 May 2013 10:08:32 +0100 Subject: [PATCH] Issue #1925660 by ACF, tim.plunkett, mtift, heddn, Cottser: Convert system's system_config_form() to SystemConfigFormBase. --- .../lib/Drupal/system/Form/CronForm.php | 125 ++++ .../lib/Drupal/system/Form/FileSystemForm.php | 91 +++ .../Drupal/system/Form/ImageToolkitForm.php | 112 +++ .../lib/Drupal/system/Form/LoggingForm.php | 56 ++ .../Drupal/system/Form/PerformanceForm.php | 172 +++++ .../lib/Drupal/system/Form/RegionalForm.php | 125 ++++ .../lib/Drupal/system/Form/RssFeedsForm.php | 70 ++ .../system/Form/SiteInformationForm.php | 184 +++++ .../system/Form/SiteMaintenanceModeForm.php | 56 ++ core/modules/system/system.admin.inc | 680 ------------------ core/modules/system/system.module | 45 +- core/modules/system/system.routing.yml | 63 ++ 12 files changed, 1063 insertions(+), 716 deletions(-) create mode 100644 core/modules/system/lib/Drupal/system/Form/CronForm.php create mode 100644 core/modules/system/lib/Drupal/system/Form/FileSystemForm.php create mode 100644 core/modules/system/lib/Drupal/system/Form/ImageToolkitForm.php create mode 100644 core/modules/system/lib/Drupal/system/Form/LoggingForm.php create mode 100644 core/modules/system/lib/Drupal/system/Form/PerformanceForm.php create mode 100644 core/modules/system/lib/Drupal/system/Form/RegionalForm.php create mode 100644 core/modules/system/lib/Drupal/system/Form/RssFeedsForm.php create mode 100644 core/modules/system/lib/Drupal/system/Form/SiteInformationForm.php create mode 100644 core/modules/system/lib/Drupal/system/Form/SiteMaintenanceModeForm.php diff --git a/core/modules/system/lib/Drupal/system/Form/CronForm.php b/core/modules/system/lib/Drupal/system/Form/CronForm.php new file mode 100644 index 000000000000..c9b91b29cc20 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Form/CronForm.php @@ -0,0 +1,125 @@ +<?php + +/** + * @file + * Contains \Drupal\system\Form\CronForm. + */ + +namespace Drupal\system\Form; + +use Drupal\Core\Config\ConfigFactory; +use Drupal\Core\Config\Context\ContextInterface; +use Drupal\Core\KeyValueStore\KeyValueFactory; +use Drupal\system\SystemConfigFormBase; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\RedirectResponse; + +/** + * Configure cron settings for this site. + */ +class CronForm extends SystemConfigFormBase { + + /** + * Stores the state storage service. + * + * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface + */ + protected $state; + + /** + * Constructs a CronForm object. + * + * @param \Drupal\Core\Config\ConfigFactory $config_factory + * The factory for configuration objects. + * @param \Drupal\Core\Config\Context\ContextInterface $context + * The configuration context used for this configuration object. + * @param \Drupal\Core\KeyValueStore\KeyValueStoreInterface $state + * The state key value store. + */ + public function __construct(ConfigFactory $config_factory, ContextInterface $context, KeyValueFactory $key_value_factory) { + parent::__construct($config_factory, $context); + $this->state = $key_value_factory->get('state'); + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('config.factory'), + $container->get('config.context.free'), + $container->get('keyvalue') + ); + } + + /** + * {@inheritdoc} + */ + public function getFormID() { + return 'system_cron_settings'; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, array &$form_state) { + $config = $this->configFactory->get('system.cron'); + + $form['description'] = array( + '#markup' => '<p>' . t('Cron takes care of running periodic tasks like checking for updates and indexing content for search.') . '</p>', + ); + $form['run'] = array( + '#type' => 'submit', + '#value' => t('Run cron'), + '#submit' => array(array($this, 'submitCron')), + ); + + $status = '<p>' . t('Last run: %cron-last ago.', array('%cron-last' => format_interval(REQUEST_TIME - $this->state->get('system.cron_last')))) . '</p>'; + $form['status'] = array( + '#markup' => $status, + ); + + $form['cron_url'] = array( + '#markup' => '<p>' . t('To run cron from outside the site, go to <a href="!cron">!cron</a>', array('!cron' => url('cron/' . $this->state->get('system.cron_key'), array('absolute' => TRUE)))) . '</p>', + ); + + $form['cron'] = array( + '#type' => 'details', + ); + $form['cron']['cron_safe_threshold'] = array( + '#type' => 'select', + '#title' => t('Run cron every'), + '#default_value' => $config->get('threshold.autorun'), + '#options' => array(0 => t('Never')) + drupal_map_assoc(array(3600, 10800, 21600, 43200, 86400, 604800), 'format_interval'), + ); + + return parent::buildForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + $this->configFactory->get('system.cron') + ->set('threshold.autorun', $form_state['values']['cron_safe_threshold']) + ->save(); + + parent::submitForm($form, $form_state); + } + + /** + * Runs cron and reloads the page. + */ + public function submitCron(array &$form, array &$form_state) { + // Run cron manually from Cron form. + if (drupal_cron_run()) { + drupal_set_message(t('Cron run successfully.')); + } + else { + drupal_set_message(t('Cron run failed.'), 'error'); + } + + return new RedirectResponse(url('admin/config/system/cron', array('absolute' => TRUE))); + } + +} diff --git a/core/modules/system/lib/Drupal/system/Form/FileSystemForm.php b/core/modules/system/lib/Drupal/system/Form/FileSystemForm.php new file mode 100644 index 000000000000..3a4aa18fc46f --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Form/FileSystemForm.php @@ -0,0 +1,91 @@ +<?php + +/** + * @file + * Contains \Drupal\system\Form\FileSystemForm. + */ + +namespace Drupal\system\Form; + +use Drupal\system\SystemConfigFormBase; + +/** + * Configure file system settings for this site. + */ +class FileSystemForm extends SystemConfigFormBase { + + /** + * {@inheritdoc} + */ + public function getFormID() { + return 'system_file_system_settings'; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, array &$form_state) { + $config = $this->configFactory->get('system.file'); + $form['file_public_path'] = array( + '#type' => 'textfield', + '#title' => t('Public file system path'), + '#default_value' => variable_get('file_public_path', conf_path() . '/files'), + '#maxlength' => 255, + '#description' => t('A local file system path where public files will be stored. This directory must exist and be writable by Drupal. This directory must be relative to the Drupal installation directory and be accessible over the web.'), + '#after_build' => array('system_check_directory'), + ); + + $form['file_private_path'] = array( + '#type' => 'textfield', + '#title' => t('Private file system path'), + '#default_value' => $config->get('path.private'), + '#maxlength' => 255, + '#description' => t('An existing local file system path for storing private files. It should be writable by Drupal and not accessible over the web. See the online handbook for <a href="@handbook">more information about securing private files</a>.', array('@handbook' => 'http://drupal.org/documentation/modules/file')), + '#after_build' => array('system_check_directory'), + ); + + $form['file_temporary_path'] = array( + '#type' => 'textfield', + '#title' => t('Temporary directory'), + '#default_value' => $config->get('path.temporary'), + '#maxlength' => 255, + '#description' => t('A local file system path where temporary files will be stored. This directory should not be accessible over the web.'), + '#after_build' => array('system_check_directory'), + ); + // Any visible, writeable wrapper can potentially be used for the files + // directory, including a remote file system that integrates with a CDN. + foreach (file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE) as $scheme => $info) { + $options[$scheme] = check_plain($info['description']); + } + + if (!empty($options)) { + $form['file_default_scheme'] = array( + '#type' => 'radios', + '#title' => t('Default download method'), + '#default_value' => $config->get('default_scheme'), + '#options' => $options, + '#description' => t('This setting is used as the preferred download method. The use of public files is more efficient, but does not provide any access control.'), + ); + } + + return parent::buildForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + $config = $this->configFactory->get('system.file') + ->set('path.private', $form_state['values']['file_private_path']) + ->set('path.temporary', $form_state['values']['file_temporary_path']); + variable_set('file_public_path', $form_state['values']['file_public_path']); + + if (isset($form_state['values']['file_default_scheme'])) { + $config->set('default_scheme', $form_state['values']['file_default_scheme']); + } + $config->save(); + + parent::submitForm($form, $form_state); + } + +} diff --git a/core/modules/system/lib/Drupal/system/Form/ImageToolkitForm.php b/core/modules/system/lib/Drupal/system/Form/ImageToolkitForm.php new file mode 100644 index 000000000000..7f2ab57aef69 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Form/ImageToolkitForm.php @@ -0,0 +1,112 @@ +<?php + +/** + * @file + * Contains \Drupal\system\Form\ImageToolkitForm. + */ + +namespace Drupal\system\Form; + +use Drupal\Core\Config\ConfigFactory; +use Drupal\Core\Config\Context\ContextInterface; +use Drupal\system\SystemConfigFormBase; +use Drupal\system\Plugin\ImageToolkitManager; +use Symfony\Component\DependencyInjection\ContainerInterface; + +/** + * Configures image toolkit settings for this site. + */ +class ImageToolkitForm extends SystemConfigFormBase { + + /** + * An array containing currently available toolkits. + * + * @var array + */ + protected $availableToolkits = array(); + + /** + * Constructs a ImageToolkitForm object. + * + * @param \Drupal\Core\Config\ConfigFactory $config_factory + * The factory for configuration objects. + * @param \Drupal\Core\Config\Context\ContextInterface $context + * The configuration context used for this configuration object. + * @param \Drupal\system\Plugin\ImageToolkitManager $manager + * The image toolkit plugin manager. + */ + public function __construct(ConfigFactory $config_factory, ContextInterface $context, ImageToolkitManager $manager) { + parent::__construct($config_factory, $context); + + foreach ($manager->getAvailableToolkits() as $id => $definition) { + $this->availableToolkits[$id] = $manager->createInstance($id); + } + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('config.factory'), + $container->get('config.context.free'), + $container->get('image.toolkit.manager') + ); + } + + /** + * {@inheritdoc} + */ + public function getFormID() { + return 'system_image_toolkit_settings'; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, array &$form_state) { + $current_toolkit = $this->configFactory->get('system.image')->get('toolkit'); + + $form['image_toolkit'] = array( + '#type' => 'radios', + '#title' => t('Select an image processing toolkit'), + '#default_value' => $current_toolkit, + '#options' => array(), + ); + + // If we have available toolkits, allow the user to select the image toolkit + // to use and load the settings forms. + foreach ($this->availableToolkits as $id => $toolkit) { + $definition = $toolkit->getDefinition(); + $form['image_toolkit']['#options'][$id] = $definition['title']; + $form['image_toolkit_settings'][$id] = array( + '#type' => 'fieldset', + '#title' => t('@toolkit settings', array('@toolkit' => $definition['title'])), + '#collapsible' => TRUE, + '#collapsed' => ($id == $current_toolkit) ? FALSE : TRUE, + '#tree' => TRUE, + ); + $form['image_toolkit_settings'][$id] += $toolkit->settingsForm(); + } + + return parent::buildForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + $this->configFactory->get('system.image') + ->set('toolkit', $form_state['values']['image_toolkit']) + ->save(); + + // Call the form submit handler for each of the toolkits. + // Get the toolkit settings forms. + foreach ($this->availableToolkits as $id => $toolkit) { + $toolkit->settingsFormSubmit($form, $form_state); + } + + parent::submitForm($form, $form_state); + } + +} diff --git a/core/modules/system/lib/Drupal/system/Form/LoggingForm.php b/core/modules/system/lib/Drupal/system/Form/LoggingForm.php new file mode 100644 index 000000000000..bc74529ed226 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Form/LoggingForm.php @@ -0,0 +1,56 @@ +<?php + +/** + * @file + * Contains \Drupal\system\Form\LoggingForm. + */ + +namespace Drupal\system\Form; + +use Drupal\system\SystemConfigFormBase; + +/** + * Configure logging settings for this site. + */ +class LoggingForm extends SystemConfigFormBase { + + /** + * {@inheritdoc} + */ + public function getFormID() { + return 'system_logging_settings'; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, array &$form_state) { + $config = $this->configFactory->get('system.logging'); + $form['error_level'] = array( + '#type' => 'radios', + '#title' => t('Error messages to display'), + '#default_value' => $config->get('error_level'), + '#options' => array( + ERROR_REPORTING_HIDE => t('None'), + ERROR_REPORTING_DISPLAY_SOME => t('Errors and warnings'), + ERROR_REPORTING_DISPLAY_ALL => t('All messages'), + ERROR_REPORTING_DISPLAY_VERBOSE => t('All messages, with backtrace information'), + ), + '#description' => t('It is recommended that sites running on production environments do not display any errors.'), + ); + + return parent::buildForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + $this->configFactory->get('system.logging') + ->set('error_level', $form_state['values']['error_level']) + ->save(); + + parent::submitForm($form, $form_state); + } + +} diff --git a/core/modules/system/lib/Drupal/system/Form/PerformanceForm.php b/core/modules/system/lib/Drupal/system/Form/PerformanceForm.php new file mode 100644 index 000000000000..92404b740f1b --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Form/PerformanceForm.php @@ -0,0 +1,172 @@ +<?php + +/** + * @file + * Contains \Drupal\system\Form\PerformanceForm. + */ + +namespace Drupal\system\Form; + +use Drupal\system\SystemConfigFormBase; +use Drupal\Core\Config\ConfigFactory; +use Drupal\Core\Config\Context\ContextInterface; +use Drupal\Core\Cache\CacheBackendInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; + +/** + * Configure performance settings for this site. + */ +class PerformanceForm extends SystemConfigFormBase { + + /** + * The page cache object. + * + * @var \Drupal\Core\Cache\CacheBackendInterface + */ + protected $pageCache; + + /** + * Constructs a PerformanceForm object. + * + * @param \Drupal\Core\Config\ConfigFactory $config_factory + * The factory for configuration objects. + * @param \Drupal\Core\Config\Context\ContextInterface $context + * The configuration context used for this configuration object. + * @param \Drupal\Core\Cache\CacheBackendInterface $page_cache + */ + public function __construct(ConfigFactory $config_factory, ContextInterface $context, CacheBackendInterface $page_cache) { + parent::__construct($config_factory, $context); + + $this->pageCache = $page_cache; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('config.factory'), + $container->get('config.context.free'), + $container->get('cache.page') + ); + } + + /** + * {@inheritdoc} + */ + public function getFormID() { + return 'system_performance_settings'; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, array &$form_state) { + $form['#attached']['library'][] = array('system', 'drupal.system'); + + $config = $this->configFactory->get('system.performance'); + + $form['clear_cache'] = array( + '#type' => 'details', + '#title' => t('Clear cache'), + ); + + $form['clear_cache']['clear'] = array( + '#type' => 'submit', + '#value' => t('Clear all caches'), + '#submit' => array(array($this, 'submitCacheClear')), + ); + + $form['caching'] = array( + '#type' => 'details', + '#title' => t('Caching'), + ); + + $period = drupal_map_assoc(array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400), 'format_interval'); + $period[0] = '<' . t('none') . '>'; + $form['caching']['page_cache_maximum_age'] = array( + '#type' => 'select', + '#title' => t('Page cache maximum age'), + '#default_value' => $config->get('cache.page.max_age'), + '#options' => $period, + '#description' => t('The maximum time a page can be cached. This is used as the value for max-age in Cache-Control headers.'), + ); + + $form['caching']['cache'] = array( + '#type' => 'checkbox', + '#title' => t('Use internal page cache'), + '#description' => t("If a reverse proxy cache isn't available, use Drupal's internal cache system to store cached pages."), + '#default_value' => $config->get('cache.page.use_internal'), + ); + + $directory = 'public://'; + $is_writable = is_dir($directory) && is_writable($directory); + $disabled = !$is_writable; + $disabled_message = ''; + if (!$is_writable) { + $disabled_message = ' ' . t('<strong class="error">Set up the <a href="!file-system">public files directory</a> to make these optimizations available.</strong>', array('!file-system' => url('admin/config/media/file-system'))); + } + + $form['bandwidth_optimization'] = array( + '#type' => 'details', + '#title' => t('Bandwidth optimization'), + '#description' => t('External resources can be optimized automatically, which can reduce both the size and number of requests made to your website.') . $disabled_message, + ); + + $js_hide = ($config->get('cache.page.max_age') > 0) ? '' : ' class="js-hide"'; + $form['bandwidth_optimization']['page_compression'] = array( + '#type' => 'checkbox', + '#title' => t('Compress cached pages.'), + '#default_value' => $config->get('response.gzip'), + '#states' => array( + 'visible' => array( + 'input[name="cache"]' => array('checked' => TRUE), + ), + ), + ); + $form['bandwidth_optimization']['preprocess_css'] = array( + '#type' => 'checkbox', + '#title' => t('Aggregate CSS files.'), + '#default_value' => $config->get('css.preprocess'), + '#disabled' => $disabled, + ); + $form['bandwidth_optimization']['preprocess_js'] = array( + '#type' => 'checkbox', + '#title' => t('Aggregate JavaScript files.'), + '#default_value' => $config->get('js.preprocess'), + '#disabled' => $disabled, + ); + + return parent::buildForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + drupal_clear_css_cache(); + drupal_clear_js_cache(); + // This form allows page compression settings to be changed, which can + // invalidate the page cache, so it needs to be cleared on form submit. + $this->pageCache->deleteAll(); + + $this->configFactory->get('system.performance') + ->set('cache.page.use_internal', $form_state['values']['cache']) + ->set('cache.page.max_age', $form_state['values']['page_cache_maximum_age']) + ->set('response.gzip', $form_state['values']['page_compression']) + ->set('css.preprocess', $form_state['values']['preprocess_css']) + ->set('js.preprocess', $form_state['values']['preprocess_js']) + ->save(); + + parent::submitForm($form, $form_state); + } + + /** + * Clears the caches. + */ + public function submitCacheClear(array &$form, array &$form_state) { + drupal_flush_all_caches(); + drupal_set_message(t('Caches cleared.')); + } + +} diff --git a/core/modules/system/lib/Drupal/system/Form/RegionalForm.php b/core/modules/system/lib/Drupal/system/Form/RegionalForm.php new file mode 100644 index 000000000000..323a3bbcfdee --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Form/RegionalForm.php @@ -0,0 +1,125 @@ +<?php + +/** + * @file + * Contains \Drupal\system\Form\RegionalForm. + */ + +namespace Drupal\system\Form; + +use Drupal\system\SystemConfigFormBase; + +/** + * Configure regional settings for this site. + */ +class RegionalForm extends SystemConfigFormBase { + + /** + * {@inheritdoc} + */ + public function getFormID() { + return 'system_regional_settings'; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, array &$form_state) { + $countries = country_get_list(); + $system_timezone = $this->configFactory->get('system.timezone'); + $system_date = $this->configFactory->get('system.date'); + + // Date settings: + $zones = system_time_zones(); + + $form['locale'] = array( + '#type' => 'details', + '#title' => t('Locale'), + ); + + $form['locale']['site_default_country'] = array( + '#type' => 'select', + '#title' => t('Default country'), + '#empty_value' => '', + '#default_value' => $system_date->get('country.default'), + '#options' => $countries, + '#attributes' => array('class' => array('country-detect')), + ); + + $form['locale']['date_first_day'] = array( + '#type' => 'select', + '#title' => t('First day of week'), + '#default_value' => $system_date->get('first_day'), + '#options' => array(0 => t('Sunday'), 1 => t('Monday'), 2 => t('Tuesday'), 3 => t('Wednesday'), 4 => t('Thursday'), 5 => t('Friday'), 6 => t('Saturday')), + ); + + $form['timezone'] = array( + '#type' => 'details', + '#title' => t('Time zones'), + ); + + $form['timezone']['date_default_timezone'] = array( + '#type' => 'select', + '#title' => t('Default time zone'), + '#default_value' => $system_timezone->get('default') ?: date_default_timezone_get(), + '#options' => $zones, + ); + + $configurable_timezones = $system_timezone->get('user.configurable'); + $form['timezone']['configurable_timezones'] = array( + '#type' => 'checkbox', + '#title' => t('Users may set their own time zone.'), + '#default_value' => $configurable_timezones, + ); + + $form['timezone']['configurable_timezones_wrapper'] = array( + '#type' => 'container', + '#states' => array( + // Hide the user configured timezone settings when users are forced to use + // the default setting. + 'invisible' => array( + 'input[name="configurable_timezones"]' => array('checked' => FALSE), + ), + ), + ); + $form['timezone']['configurable_timezones_wrapper']['empty_timezone_message'] = array( + '#type' => 'checkbox', + '#title' => t('Remind users at login if their time zone is not set.'), + '#default_value' => $system_timezone->get('user.warn'), + '#description' => t('Only applied if users may set their own time zone.') + ); + + $form['timezone']['configurable_timezones_wrapper']['user_default_timezone'] = array( + '#type' => 'radios', + '#title' => t('Time zone for new users'), + '#default_value' => $system_timezone->get('user.default'), + '#options' => array( + DRUPAL_USER_TIMEZONE_DEFAULT => t('Default time zone.'), + DRUPAL_USER_TIMEZONE_EMPTY => t('Empty time zone.'), + DRUPAL_USER_TIMEZONE_SELECT => t('Users may set their own time zone at registration.'), + ), + '#description' => t('Only applied if users may set their own time zone.') + ); + + return parent::buildForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + $this->configFactory->get('system.date') + ->set('country.default', $form_state['values']['site_default_country']) + ->set('first_day', $form_state['values']['date_first_day']) + ->save(); + $this->configFactory->get('system.timezone') + ->set('default', $form_state['values']['date_default_timezone']) + ->set('user.configurable', $form_state['values']['configurable_timezones']) + ->set('user.warn', $form_state['values']['empty_timezone_message']) + ->set('user.default', $form_state['values']['user_default_timezone']) + ->save(); + + parent::submitForm($form, $form_state); + } + +} diff --git a/core/modules/system/lib/Drupal/system/Form/RssFeedsForm.php b/core/modules/system/lib/Drupal/system/Form/RssFeedsForm.php new file mode 100644 index 000000000000..189932446772 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Form/RssFeedsForm.php @@ -0,0 +1,70 @@ +<?php + +/** + * @file + * Contains \Drupal\system\Form\RssFeedsForm. + */ + +namespace Drupal\system\Form; + +use Drupal\system\SystemConfigFormBase; + +/** + * Configure RSS settings for this site. + */ +class RssFeedsForm extends SystemConfigFormBase { + + /** + * {@inheritdoc} + */ + public function getFormID() { + return 'system_rss_feeds_settings'; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, array &$form_state) { + $rss_config = $this->configFactory->get('system.rss'); + $form['feed_description'] = array( + '#type' => 'textarea', + '#title' => t('Feed description'), + '#default_value' => $rss_config->get('channel.description'), + '#description' => t('Description of your site, included in each feed.') + ); + $form['feed_default_items'] = array( + '#type' => 'select', + '#title' => t('Number of items in each feed'), + '#default_value' => $rss_config->get('items.limit'), + '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)), + '#description' => t('Default number of items to include in each feed.') + ); + $form['feed_item_length'] = array( + '#type' => 'select', + '#title' => t('Feed content'), + '#default_value' => $rss_config->get('items.view_mode'), + '#options' => array( + 'title' => t('Titles only'), + 'teaser' => t('Titles plus teaser'), + 'fulltext' => t('Full text'), + ), + '#description' => t('Global setting for the default display of content items in each feed.') + ); + + return parent::buildForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + $this->configFactory->get('system.rss') + ->set('channel.description', $form_state['values']['feed_description']) + ->set('items.limit', $form_state['values']['feed_default_items']) + ->set('items.view_mode', $form_state['values']['feed_item_length']) + ->save(); + + parent::submitForm($form, $form_state); + } + +} diff --git a/core/modules/system/lib/Drupal/system/Form/SiteInformationForm.php b/core/modules/system/lib/Drupal/system/Form/SiteInformationForm.php new file mode 100644 index 000000000000..55b1175cb69a --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Form/SiteInformationForm.php @@ -0,0 +1,184 @@ +<?php + +/** + * @file + * Contains \Drupal\system\Form\SiteInformationForm. + */ + +namespace Drupal\system\Form; + +use Drupal\Core\Config\ConfigFactory; +use Drupal\Core\Config\Context\ContextInterface; +use Drupal\Core\Path\AliasManagerInterface; +use Drupal\system\SystemConfigFormBase; +use Symfony\Component\DependencyInjection\ContainerInterface; + +/** + * Configure site information settings for this site. + */ +class SiteInformationForm extends SystemConfigFormBase { + + /** + * The path alias manager. + * + * @var \Drupal\Core\Path\AliasManagerInterface + */ + protected $aliasManager; + + /** + * Constructs a SiteInformationForm object. + * + * @param \Drupal\Core\Config\ConfigFactory $config_factory + * The factory for configuration objects. + * @param \Drupal\Core\Config\Context\ContextInterface $context + * The configuration context used for this configuration object. + * @param \Drupal\Core\Path\AliasManagerInterface $alias_manager + * The path alias manager. + */ + public function __construct(ConfigFactory $config_factory, ContextInterface $context, AliasManagerInterface $alias_manager) { + parent::__construct($config_factory, $context); + + $this->aliasManager = $alias_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('config.factory'), + $container->get('config.context.free'), + $container->get('path.alias_manager') + ); + } + + /** + * {@inheritdoc} + */ + public function getFormID() { + return 'system_site_information_settings'; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, array &$form_state) { + $site_config = $this->configFactory->get('system.site'); + $site_mail = $site_config->get('mail'); + if (empty($site_mail)) { + $site_mail = ini_get('sendmail_from'); + } + + $form['site_information'] = array( + '#type' => 'details', + '#title' => t('Site details'), + ); + $form['site_information']['site_name'] = array( + '#type' => 'textfield', + '#title' => t('Site name'), + '#default_value' => $site_config->get('name'), + '#required' => TRUE + ); + $form['site_information']['site_slogan'] = array( + '#type' => 'textfield', + '#title' => t('Slogan'), + '#default_value' => $site_config->get('slogan'), + '#description' => t("How this is used depends on your site's theme."), + ); + $form['site_information']['site_mail'] = array( + '#type' => 'email', + '#title' => t('E-mail address'), + '#default_value' => $site_mail, + '#description' => t("The <em>From</em> address in automated e-mails sent during registration and new password requests, and other notifications. (Use an address ending in your site's domain to help prevent this e-mail being flagged as spam.)"), + '#required' => TRUE, + ); + $form['front_page'] = array( + '#type' => 'details', + '#title' => t('Front page'), + ); + $front_page = $site_config->get('page.front') != 'user' ? $this->aliasManager->getPathAlias($site_config->get('page.front')) : ''; + $form['front_page']['site_frontpage'] = array( + '#type' => 'textfield', + '#title' => t('Default front page'), + '#default_value' => $front_page, + '#size' => 40, + '#description' => t('Optionally, specify a relative URL to display as the front page. Leave blank to display the default front page.'), + '#field_prefix' => url(NULL, array('absolute' => TRUE)), + ); + $form['error_page'] = array( + '#type' => 'details', + '#title' => t('Error pages'), + ); + $form['error_page']['site_403'] = array( + '#type' => 'textfield', + '#title' => t('Default 403 (access denied) page'), + '#default_value' => $site_config->get('page.403'), + '#size' => 40, + '#description' => t('This page is displayed when the requested document is denied to the current user. Leave blank to display a generic "access denied" page.'), + '#field_prefix' => url(NULL, array('absolute' => TRUE)), + ); + $form['error_page']['site_404'] = array( + '#type' => 'textfield', + '#title' => t('Default 404 (not found) page'), + '#default_value' => $site_config->get('page.404'), + '#size' => 40, + '#description' => t('This page is displayed when no other content matches the requested document. Leave blank to display a generic "page not found" page.'), + '#field_prefix' => url(NULL, array('absolute' => TRUE)), + ); + + return parent::buildForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function validateForm(array &$form, array &$form_state) { + // Check for empty front page path. + if (empty($form_state['values']['site_frontpage'])) { + // Set to default "user". + form_set_value($form['front_page']['site_frontpage'], 'user', $form_state); + } + else { + // Get the normal path of the front page. + form_set_value($form['front_page']['site_frontpage'], $this->aliasManager->getSystemPath($form_state['values']['site_frontpage']), $form_state); + } + // Validate front page path. + if (!drupal_valid_path($form_state['values']['site_frontpage'])) { + form_set_error('site_frontpage', t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state['values']['site_frontpage']))); + } + // Get the normal paths of both error pages. + if (!empty($form_state['values']['site_403'])) { + form_set_value($form['error_page']['site_403'], $this->aliasManager->getSystemPath($form_state['values']['site_403']), $form_state); + } + if (!empty($form_state['values']['site_404'])) { + form_set_value($form['error_page']['site_404'], $this->aliasManager->getSystemPath($form_state['values']['site_404']), $form_state); + } + // Validate 403 error path. + if (!empty($form_state['values']['site_403']) && !drupal_valid_path($form_state['values']['site_403'])) { + form_set_error('site_403', t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state['values']['site_403']))); + } + // Validate 404 error path. + if (!empty($form_state['values']['site_404']) && !drupal_valid_path($form_state['values']['site_404'])) { + form_set_error('site_404', t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state['values']['site_404']))); + } + + parent::validateForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + $this->configFactory->get('system.site') + ->set('name', $form_state['values']['site_name']) + ->set('mail', $form_state['values']['site_mail']) + ->set('slogan', $form_state['values']['site_slogan']) + ->set('page.front', $form_state['values']['site_frontpage']) + ->set('page.403', $form_state['values']['site_403']) + ->set('page.404', $form_state['values']['site_404']) + ->save(); + + parent::submitForm($form, $form_state); + } + +} diff --git a/core/modules/system/lib/Drupal/system/Form/SiteMaintenanceModeForm.php b/core/modules/system/lib/Drupal/system/Form/SiteMaintenanceModeForm.php new file mode 100644 index 000000000000..a196cdaaeebb --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Form/SiteMaintenanceModeForm.php @@ -0,0 +1,56 @@ +<?php + +/** + * @file + * Contains \Drupal\system\Form\SiteMaintenanceModeForm. + */ + +namespace Drupal\system\Form; + +use Drupal\system\SystemConfigFormBase; + +/** + * Configure maintenance settings for this site. + */ +class SiteMaintenanceModeForm extends SystemConfigFormBase { + + /** + * {@inheritdoc} + */ + public function getFormID() { + return 'system_site_maintenance_mode'; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, array &$form_state) { + $config = $this->configFactory->get('system.maintenance'); + $form['maintenance_mode'] = array( + '#type' => 'checkbox', + '#title' => t('Put site into maintenance mode'), + '#default_value' => $config->get('enabled'), + '#description' => t('Visitors will only see the maintenance mode message. Only users with the "Access site in maintenance mode" <a href="@permissions-url">permission</a> will be able to access the site. Authorized users can log in directly via the <a href="@user-login">user login</a> page.', array('@permissions-url' => url('admin/config/people/permissions'), '@user-login' => url('user'))), + ); + $form['maintenance_mode_message'] = array( + '#type' => 'textarea', + '#title' => t('Message to display when in maintenance mode'), + '#default_value' => $config->get('message'), + ); + + return parent::buildForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + $this->configFactory->get('system.maintenance') + ->set('enabled', $form_state['values']['maintenance_mode']) + ->set('message', $form_state['values']['maintenance_mode_message']) + ->save(); + + parent::submitForm($form, $form_state); + } + +} diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index c6002f95f778..d344d37509ca 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -1414,686 +1414,6 @@ function system_modules_uninstall_submit($form, &$form_state) { } } -/** - * Form builder; The general site information form. - * - * @ingroup forms - * @see system_config_form() - */ -function system_site_information_settings($form, &$form_state) { - config_context_enter('config.context.free'); - $site_config = config('system.site'); - $site_mail = $site_config->get('mail'); - if (empty($site_mail)) { - $site_mail = ini_get('sendmail_from'); - } - - $form['site_information'] = array( - '#type' => 'details', - '#title' => t('Site details'), - ); - $form['site_information']['site_name'] = array( - '#type' => 'textfield', - '#title' => t('Site name'), - '#default_value' => $site_config->get('name'), - '#required' => TRUE - ); - $form['site_information']['site_slogan'] = array( - '#type' => 'textfield', - '#title' => t('Slogan'), - '#default_value' => $site_config->get('slogan'), - '#description' => t("How this is used depends on your site's theme."), - ); - $form['site_information']['site_mail'] = array( - '#type' => 'email', - '#title' => t('E-mail address'), - '#default_value' => $site_mail, - '#description' => t("The <em>From</em> address in automated e-mails sent during registration and new password requests, and other notifications. (Use an address ending in your site's domain to help prevent this e-mail being flagged as spam.)"), - '#required' => TRUE, - ); - $form['front_page'] = array( - '#type' => 'details', - '#title' => t('Front page'), - ); - $front_page = $site_config->get('page.front') != 'user' ? drupal_container()->get('path.alias_manager')->getPathAlias($site_config->get('page.front')) : ''; - $form['front_page']['site_frontpage'] = array( - '#type' => 'textfield', - '#title' => t('Default front page'), - '#default_value' => $front_page, - '#size' => 40, - '#description' => t('Optionally, specify a relative URL to display as the front page. Leave blank to display the default front page.'), - '#field_prefix' => url(NULL, array('absolute' => TRUE)), - ); - $form['error_page'] = array( - '#type' => 'details', - '#title' => t('Error pages'), - ); - $form['error_page']['site_403'] = array( - '#type' => 'textfield', - '#title' => t('Default 403 (access denied) page'), - '#default_value' => $site_config->get('page.403'), - '#size' => 40, - '#description' => t('This page is displayed when the requested document is denied to the current user. Leave blank to display a generic "access denied" page.'), - '#field_prefix' => url(NULL, array('absolute' => TRUE)), - ); - $form['error_page']['site_404'] = array( - '#type' => 'textfield', - '#title' => t('Default 404 (not found) page'), - '#default_value' => $site_config->get('page.404'), - '#size' => 40, - '#description' => t('This page is displayed when no other content matches the requested document. Leave blank to display a generic "page not found" page.'), - '#field_prefix' => url(NULL, array('absolute' => TRUE)), - ); - - $form['#validate'][] = 'system_site_information_settings_validate'; - - return system_config_form($form, $form_state); -} - -/** - * Validates the submitted site-information form. - */ -function system_site_information_settings_validate($form, &$form_state) { - // Check for empty front page path. - if (empty($form_state['values']['site_frontpage'])) { - // Set to default "user". - form_set_value($form['front_page']['site_frontpage'], 'user', $form_state); - } - else { - // Get the normal path of the front page. - form_set_value($form['front_page']['site_frontpage'], drupal_container()->get('path.alias_manager')->getSystemPath($form_state['values']['site_frontpage']), $form_state); - } - // Validate front page path. - if (!drupal_valid_path($form_state['values']['site_frontpage'])) { - form_set_error('site_frontpage', t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state['values']['site_frontpage']))); - } - // Get the normal paths of both error pages. - if (!empty($form_state['values']['site_403'])) { - form_set_value($form['error_page']['site_403'], drupal_container()->get('path.alias_manager')->getSystemPath($form_state['values']['site_403']), $form_state); - } - if (!empty($form_state['values']['site_404'])) { - form_set_value($form['error_page']['site_404'], drupal_container()->get('path.alias_manager')->getSystemPath($form_state['values']['site_404']), $form_state); - } - // Validate 403 error path. - if (!empty($form_state['values']['site_403']) && !drupal_valid_path($form_state['values']['site_403'])) { - form_set_error('site_403', t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state['values']['site_403']))); - } - // Validate 404 error path. - if (!empty($form_state['values']['site_404']) && !drupal_valid_path($form_state['values']['site_404'])) { - form_set_error('site_404', t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state['values']['site_404']))); - } -} - -/** - * Form submission handler for system_site_information_settings(). - */ -function system_site_information_settings_submit($form, &$form_state) { - config_context_enter('config.context.free'); - config('system.site') - ->set('name', $form_state['values']['site_name']) - ->set('mail', $form_state['values']['site_mail']) - ->set('slogan', $form_state['values']['site_slogan']) - ->set('page.front', $form_state['values']['site_frontpage']) - ->set('page.403', $form_state['values']['site_403']) - ->set('page.404', $form_state['values']['site_404']) - ->save(); -} - -/** - * Form builder; Cron form. - * - * @ingroup forms - */ -function system_cron_settings($form, &$form_state) { - config_context_enter('config.context.free'); - $form['description'] = array( - '#markup' => '<p>' . t('Cron takes care of running periodic tasks like checking for updates and indexing content for search.') . '</p>', - ); - $form['run'] = array( - '#type' => 'submit', - '#value' => t('Run cron'), - '#submit' => array('system_run_cron_submit'), - ); - - $status = '<p>' . t('Last run: %cron-last ago.', array('%cron-last' => format_interval(REQUEST_TIME - state()->get('system.cron_last')))) . '</p>'; - $form['status'] = array( - '#markup' => $status, - ); - - $form['cron_url'] = array( - '#markup' => '<p>' . t('To run cron from outside the site, go to <a href="!cron">!cron</a>', array('!cron' => url('cron/' . state()->get('system.cron_key'), array('absolute' => TRUE)))) . '</p>', - ); - - $form['cron'] = array( - '#type' => 'details', - ); - $form['cron']['cron_safe_threshold'] = array( - '#type' => 'select', - '#title' => t('Run cron every'), - '#default_value' => config('system.cron')->get('threshold.autorun'), - '#options' => array(0 => t('Never')) + drupal_map_assoc(array(3600, 10800, 21600, 43200, 86400, 604800), 'format_interval'), - ); - - return system_config_form($form, $form_state); -} - -/** - * Form builder submit handler; Handle submission for cron settings. - * - * @ingroup forms - */ -function system_cron_settings_submit($form, &$form_state) { - config_context_enter('config.context.free'); - config('system.cron') - ->set('threshold.autorun', $form_state['values']['cron_safe_threshold']) - ->save(); -} - -/** - * Submit callback; run cron. - * - * @ingroup forms - */ -function system_run_cron_submit($form, &$form_state) { - // Run cron manually from Cron form. - if (drupal_cron_run()) { - drupal_set_message(t('Cron run successfully.')); - } - else { - drupal_set_message(t('Cron run failed.'), 'error'); - } - - drupal_goto('admin/config/system/cron'); -} - -/** - * Form builder; Configure error reporting settings. - * - * @ingroup forms - * @see system_logging_settings_submit() - */ -function system_logging_settings($form, &$form_state) { - config_context_enter('config.context.free'); - $form['error_level'] = array( - '#type' => 'radios', - '#title' => t('Error messages to display'), - '#default_value' => config('system.logging')->get('error_level'), - '#options' => array( - ERROR_REPORTING_HIDE => t('None'), - ERROR_REPORTING_DISPLAY_SOME => t('Errors and warnings'), - ERROR_REPORTING_DISPLAY_ALL => t('All messages'), - ERROR_REPORTING_DISPLAY_VERBOSE => t('All messages, with backtrace information'), - ), - '#description' => t('It is recommended that sites running on production environments do not display any errors.'), - ); - - return system_config_form($form, $form_state); -} - -/** - * Form submission handler for system_logging_settings(). - * - * @ingroup forms - */ -function system_logging_settings_submit($form, &$form_state) { - config_context_enter('config.context.free'); - config('system.logging') - ->set('error_level', $form_state['values']['error_level']) - ->save(); -} - -/** - * Form builder; Configure site performance settings. - * - * @ingroup forms - * @see system_performance_settings_submit(). - */ -function system_performance_settings($form, &$form_state) { - drupal_add_library('system', 'drupal.system'); - config_context_enter('config.context.free'); - $config = config('system.performance'); - - $form['clear_cache'] = array( - '#type' => 'details', - '#title' => t('Clear cache'), - ); - - $form['clear_cache']['clear'] = array( - '#type' => 'submit', - '#value' => t('Clear all caches'), - '#submit' => array('system_clear_cache_submit'), - ); - - $form['caching'] = array( - '#type' => 'details', - '#title' => t('Caching'), - ); - - $period = drupal_map_assoc(array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400), 'format_interval'); - $period[0] = '<' . t('none') . '>'; - $form['caching']['page_cache_maximum_age'] = array( - '#type' => 'select', - '#title' => t('Page cache maximum age'), - '#default_value' => $config->get('cache.page.max_age'), - '#options' => $period, - '#description' => t('The maximum time a page can be cached. This is used as the value for max-age in Cache-Control headers.'), - ); - - $form['caching']['cache'] = array( - '#type' => 'checkbox', - '#title' => t('Use internal page cache'), - '#description' => t("If a reverse proxy cache isn't available, use Drupal's internal cache system to store cached pages."), - '#default_value' => $config->get('cache.page.use_internal'), - ); - - $directory = 'public://'; - $is_writable = is_dir($directory) && is_writable($directory); - $disabled = !$is_writable; - $disabled_message = ''; - if (!$is_writable) { - $disabled_message = ' ' . t('<strong class="error">Set up the <a href="!file-system">public files directory</a> to make these optimizations available.</strong>', array('!file-system' => url('admin/config/media/file-system'))); - } - - $form['bandwidth_optimization'] = array( - '#type' => 'details', - '#title' => t('Bandwidth optimization'), - '#description' => t('External resources can be optimized automatically, which can reduce both the size and number of requests made to your website.') . $disabled_message, - ); - - $js_hide = ($config->get('cache.page.max_age') > 0) ? '' : ' class="js-hide"'; - $form['bandwidth_optimization']['page_compression'] = array( - '#type' => 'checkbox', - '#title' => t('Compress cached pages.'), - '#default_value' => $config->get('response.gzip'), - '#states' => array( - 'visible' => array( - 'input[name="cache"]' => array('checked' => TRUE), - ), - ), - ); - $form['bandwidth_optimization']['preprocess_css'] = array( - '#type' => 'checkbox', - '#title' => t('Aggregate CSS files.'), - '#default_value' => $config->get('css.preprocess'), - '#disabled' => $disabled, - ); - $form['bandwidth_optimization']['preprocess_js'] = array( - '#type' => 'checkbox', - '#title' => t('Aggregate JavaScript files.'), - '#default_value' => $config->get('js.preprocess'), - '#disabled' => $disabled, - ); - - $form['#submit'][] = 'drupal_clear_css_cache'; - $form['#submit'][] = 'drupal_clear_js_cache'; - // This form allows page compression settings to be changed, which can - // invalidate the page cache, so it needs to be cleared on form submit. - $form['#submit'][] = 'system_clear_page_cache_submit'; - $form['#submit'][] = 'system_performance_settings_submit'; - - return system_config_form($form, $form_state); -} - -/** - * Form submission handler for system_performance_settings(). - * - * @ingroup forms - */ -function system_performance_settings_submit($form, &$form_state) { - config_context_enter('config.context.free'); - $config = config('system.performance'); - $config->set('cache.page.use_internal', $form_state['values']['cache']); - $config->set('cache.page.max_age', $form_state['values']['page_cache_maximum_age']); - $config->set('response.gzip', $form_state['values']['page_compression']); - $config->set('css.preprocess', $form_state['values']['preprocess_css']); - $config->set('js.preprocess', $form_state['values']['preprocess_js']); - $config->save(); -} - -/** - * Submit callback; clear system caches. - * - * @ingroup forms - */ -function system_clear_cache_submit($form, &$form_state) { - drupal_flush_all_caches(); - drupal_set_message(t('Caches cleared.')); -} - -/** - * Submit callback; clear the page cache. - * - * @ingroup forms - */ -function system_clear_page_cache_submit($form, &$form_state) { - cache('page')->deleteAll(); -} - -/** - * Form builder; Configure the site file handling. - * - * @ingroup forms - * @see system_file_system_settings_submit() - */ -function system_file_system_settings($form, $form_state) { - $config = config('system.file'); - $form['file_public_path'] = array( - '#type' => 'textfield', - '#title' => t('Public file system path'), - '#default_value' => variable_get('file_public_path', conf_path() . '/files'), - '#maxlength' => 255, - '#description' => t('A local file system path where public files will be stored. This directory must exist and be writable by Drupal. This directory must be relative to the Drupal installation directory and be accessible over the web.'), - '#after_build' => array('system_check_directory'), - ); - - $form['file_private_path'] = array( - '#type' => 'textfield', - '#title' => t('Private file system path'), - '#default_value' => $config->get('path.private'), - '#maxlength' => 255, - '#description' => t('An existing local file system path for storing private files. It should be writable by Drupal and not accessible over the web. See the online handbook for <a href="@handbook">more information about securing private files</a>.', array('@handbook' => 'http://drupal.org/documentation/modules/file')), - '#after_build' => array('system_check_directory'), - ); - - $form['file_temporary_path'] = array( - '#type' => 'textfield', - '#title' => t('Temporary directory'), - '#default_value' => $config->get('path.temporary'), - '#maxlength' => 255, - '#description' => t('A local file system path where temporary files will be stored. This directory should not be accessible over the web.'), - '#after_build' => array('system_check_directory'), - ); - // Any visible, writeable wrapper can potentially be used for the files - // directory, including a remote file system that integrates with a CDN. - foreach (file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE) as $scheme => $info) { - $options[$scheme] = check_plain($info['description']); - } - - if (!empty($options)) { - $form['file_default_scheme'] = array( - '#type' => 'radios', - '#title' => t('Default download method'), - '#default_value' => $config->get('default_scheme'), - '#options' => $options, - '#description' => t('This setting is used as the preferred download method. The use of public files is more efficient, but does not provide any access control.'), - ); - } - - return system_config_form($form, $form_state); -} - -/** - * Save configuration values for file system. - * - * @ingroup forms - * @see system_file_system_settings() - */ -function system_file_system_settings_submit($form, &$form_state) { - $config = config('system.file') - ->set('path.private', $form_state['values']['file_private_path']) - ->set('path.temporary', $form_state['values']['file_temporary_path']); - variable_set('file_public_path', $form_state['values']['file_public_path']); - - - if(isset($form_state['values']['file_default_scheme'])) { - $config->set('default_scheme', $form_state['values']['file_default_scheme']); - } - $config->save(); -} - -/** - * Form builder; Configure site image toolkit usage. - * - * @ingroup forms - * @see system_image_toolkit_settings_submit() - */ -function system_image_toolkit_settings($form, &$form_state) { - $manager = Drupal::service('image.toolkit.manager'); - $toolkits_available = $manager->getAvailableToolkits(); - $current_toolkit = config('system.image')->get('toolkit'); - - // If we have available toolkits allow the user to select the image toolkit to - // use and load the settings forms. - $options = array(); - foreach($toolkits_available as $id => $definition) { - $options[$id] = $definition['title']; - } - - $form['image_toolkit'] = array( - '#type' => 'radios', - '#title' => t('Select an image processing toolkit'), - '#default_value' => $current_toolkit, - '#options' => $options, - ); - - // Get the toolkit settings forms. - foreach ($toolkits_available as $id => $definition) { - $toolkit = $manager->createInstance($id); - $form['image_toolkit_settings'][$id] = array( - '#type' => 'fieldset', - '#title' => t('@toolkit settings', array('@toolkit' => $definition['title'])), - '#collapsible' => TRUE, - '#collapsed' => ($id == $current_toolkit) ? FALSE : TRUE, - '#tree' => TRUE, - ); - $form['image_toolkit_settings'][$id] += $toolkit->settingsForm(); - } - - $form = system_config_form($form, $form_state); - - return $form; -} - -/** - * Form submission handler for system_image_toolkit_settings(). - */ -function system_image_toolkit_settings_submit($form, &$form_state) { - config('system.image') - ->set('toolkit', $form_state['values']['image_toolkit']) - ->save(); - - // Call the form submit handler for each of the toolkits. - // Get the toolkit settings forms. - $manager = Drupal::service('image.toolkit.manager'); - foreach ($manager->getAvailableToolkits() as $id => $definition) { - $toolkit = $manager->createInstance($id); - $toolkit->settingsFormSubmit($form, $form_state); - } -} - -/** - * Form builder; Configure how the site handles RSS feeds. - * - * @ingroup forms - */ -function system_rss_feeds_settings($form, &$form_state) { - config_context_enter('config.context.free'); - $rss_config = config('system.rss'); - $form['feed_description'] = array( - '#type' => 'textarea', - '#title' => t('Feed description'), - '#default_value' => $rss_config->get('channel.description'), - '#description' => t('Description of your site, included in each feed.') - ); - $form['feed_default_items'] = array( - '#type' => 'select', - '#title' => t('Number of items in each feed'), - '#default_value' => $rss_config->get('items.limit'), - '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)), - '#description' => t('Default number of items to include in each feed.') - ); - $form['feed_item_length'] = array( - '#type' => 'select', - '#title' => t('Feed content'), - '#default_value' => $rss_config->get('items.view_mode'), - '#options' => array( - 'title' => t('Titles only'), - 'teaser' => t('Titles plus teaser'), - 'fulltext' => t('Full text'), - ), - '#description' => t('Global setting for the default display of content items in each feed.') - ); - - return system_config_form($form, $form_state); -} - -/** - * Form builder submit handler; Handle submission for RSS feeds settings. - * - * @ingroup forms - */ -function system_rss_feeds_settings_submit($form, &$form_state) { - config_context_enter('config.context.free'); - config('system.rss') - ->set('channel.description', $form_state['values']['feed_description']) - ->set('items.limit', $form_state['values']['feed_default_items']) - ->set('items.view_mode', $form_state['values']['feed_item_length']) - ->save(); -} - -/** - * Form builder; Configure the site regional settings. - * - * @ingroup forms - * @see system_config_form() - * @see system_regional_settings_submit() - */ -function system_regional_settings($form, &$form_state) { - $countries = country_get_list(); - $system_timezone = config('system.timezone'); - $system_date = config('system.date'); - - // Date settings: - $zones = system_time_zones(); - - $form['locale'] = array( - '#type' => 'details', - '#title' => t('Locale'), - ); - - $form['locale']['site_default_country'] = array( - '#type' => 'select', - '#title' => t('Default country'), - '#empty_value' => '', - '#default_value' => $system_date->get('country.default'), - '#options' => $countries, - '#attributes' => array('class' => array('country-detect')), - ); - - $form['locale']['date_first_day'] = array( - '#type' => 'select', - '#title' => t('First day of week'), - '#default_value' => $system_date->get('first_day'), - '#options' => array(0 => t('Sunday'), 1 => t('Monday'), 2 => t('Tuesday'), 3 => t('Wednesday'), 4 => t('Thursday'), 5 => t('Friday'), 6 => t('Saturday')), - ); - - $form['timezone'] = array( - '#type' => 'details', - '#title' => t('Time zones'), - ); - - $form['timezone']['date_default_timezone'] = array( - '#type' => 'select', - '#title' => t('Default time zone'), - '#default_value' => $system_timezone->get('default') ?: date_default_timezone_get(), - '#options' => $zones, - ); - - $configurable_timezones = $system_timezone->get('user.configurable'); - $form['timezone']['configurable_timezones'] = array( - '#type' => 'checkbox', - '#title' => t('Users may set their own time zone.'), - '#default_value' => $configurable_timezones, - ); - - $form['timezone']['configurable_timezones_wrapper'] = array( - '#type' => 'container', - '#states' => array( - // Hide the user configured timezone settings when users are forced to use - // the default setting. - 'invisible' => array( - 'input[name="configurable_timezones"]' => array('checked' => FALSE), - ), - ), - ); - $form['timezone']['configurable_timezones_wrapper']['empty_timezone_message'] = array( - '#type' => 'checkbox', - '#title' => t('Remind users at login if their time zone is not set.'), - '#default_value' => $system_timezone->get('user.warn'), - '#description' => t('Only applied if users may set their own time zone.') - ); - - $form['timezone']['configurable_timezones_wrapper']['user_default_timezone'] = array( - '#type' => 'radios', - '#title' => t('Time zone for new users'), - '#default_value' => $system_timezone->get('user.default'), - '#options' => array( - DRUPAL_USER_TIMEZONE_DEFAULT => t('Default time zone.'), - DRUPAL_USER_TIMEZONE_EMPTY => t('Empty time zone.'), - DRUPAL_USER_TIMEZONE_SELECT => t('Users may set their own time zone at registration.'), - ), - '#description' => t('Only applied if users may set their own time zone.') - ); - - return system_config_form($form, $form_state); -} - -/** - * Form builder submit handler; Handles submission for regional settings. - * - * @ingroup forms - * @see system_regional_settings() - */ -function system_regional_settings_submit($form, &$form_state) { - config('system.date') - ->set('country.default', $form_state['values']['site_default_country']) - ->set('first_day', $form_state['values']['date_first_day']) - ->save(); - config('system.timezone') - ->set('default', $form_state['values']['date_default_timezone']) - ->set('user.configurable', $form_state['values']['configurable_timezones']) - ->set('user.warn', $form_state['values']['empty_timezone_message']) - ->set('user.default', $form_state['values']['user_default_timezone']) - ->save(); -} - -/** - * Form builder; Configure the site's maintenance status. - * - * @ingroup forms - * @see system_site_maintenance_mode_submit() - */ -function system_site_maintenance_mode($form, &$form_state) { - config_context_enter('config.context.free'); - $config = config('system.maintenance'); - $form['maintenance_mode'] = array( - '#type' => 'checkbox', - '#title' => t('Put site into maintenance mode'), - '#default_value' => $config->get('enabled'), - '#description' => t('Visitors will only see the maintenance mode message. Only users with the "Access site in maintenance mode" <a href="@permissions-url">permission</a> will be able to access the site. Authorized users can log in directly via the <a href="@user-login">user login</a> page.', array('@permissions-url' => url('admin/config/people/permissions'), '@user-login' => url('user'))), - ); - $form['maintenance_mode_message'] = array( - '#type' => 'textarea', - '#title' => t('Message to display when in maintenance mode'), - '#default_value' => $config->get('message'), - ); - - return system_config_form($form, $form_state); -} - -/** - * Form submission handler for system_site_maintenance_mode(). - * - * @ingroup forms - */ -function system_site_maintenance_mode_submit($form, &$form_state) { - config_context_enter('config.context.free'); - config('system.maintenance') - ->set('enabled', $form_state['values']['maintenance_mode']) - ->set('message', $form_state['values']['maintenance_mode_message']) - ->save(); -} - /** * Menu callback: displays the site status report. Can also be used as a pure check. * diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 918acde19208..4d2f61ee3633 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -806,20 +806,14 @@ function system_menu() { $items['admin/config/media/file-system'] = array( 'title' => 'File system', 'description' => 'Tell Drupal where to store uploaded files and how they are accessed.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('system_file_system_settings'), - 'access arguments' => array('administer site configuration'), + 'route_name' => 'system_file_system_settings', 'weight' => -10, - 'file' => 'system.admin.inc', ); $items['admin/config/media/image-toolkit'] = array( 'title' => 'Image toolkit', 'description' => 'Choose which image toolkit to use if you have installed optional toolkits.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('system_image_toolkit_settings'), - 'access arguments' => array('administer site configuration'), + 'route_name' => 'system_image_toolkit_settings', 'weight' => 20, - 'file' => 'system.admin.inc', ); // Service settings. @@ -835,10 +829,7 @@ function system_menu() { $items['admin/config/services/rss-publishing'] = array( 'title' => 'RSS publishing', 'description' => 'Configure the site description, the number of items per feed and whether feeds should be titles/teasers/full-text.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('system_rss_feeds_settings'), - 'access arguments' => array('administer site configuration'), - 'file' => 'system.admin.inc', + 'route_name' => 'system_rss_feeds_settings', ); // Development settings. @@ -854,28 +845,19 @@ function system_menu() { $items['admin/config/development/maintenance'] = array( 'title' => 'Maintenance mode', 'description' => 'Take the site offline for maintenance or bring it back online.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('system_site_maintenance_mode'), - 'access arguments' => array('administer site configuration'), - 'file' => 'system.admin.inc', + 'route_name' => 'system_site_maintenance_mode', 'weight' => -10, ); $items['admin/config/development/performance'] = array( 'title' => 'Performance', 'description' => 'Enable or disable page caching for anonymous users and set CSS and JS bandwidth optimization options.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('system_performance_settings'), - 'access arguments' => array('administer site configuration'), - 'file' => 'system.admin.inc', + 'route_name' => 'system_performance_settings', 'weight' => -20, ); $items['admin/config/development/logging'] = array( 'title' => 'Logging and errors', 'description' => "Settings for logging and alerts modules. Various modules can route Drupal's system events to different destinations, such as syslog, database, email, etc.", - 'page callback' => 'drupal_get_form', - 'page arguments' => array('system_logging_settings'), - 'access arguments' => array('administer site configuration'), - 'file' => 'system.admin.inc', + 'route_name' => 'system_logging_settings', 'weight' => -15, ); @@ -892,11 +874,8 @@ function system_menu() { $items['admin/config/regional/settings'] = array( 'title' => 'Regional settings', 'description' => "Settings for the site's default time zone and country.", - 'page callback' => 'drupal_get_form', - 'page arguments' => array('system_regional_settings'), - 'access arguments' => array('administer site configuration'), + 'route_name' => 'system_regional_settings', 'weight' => -20, - 'file' => 'system.admin.inc', ); $items['admin/config/regional/date-time'] = array( 'title' => 'Date and time formats', @@ -964,19 +943,13 @@ function system_menu() { $items['admin/config/system/site-information'] = array( 'title' => 'Site information', 'description' => 'Change site name, e-mail address, slogan, default front page, and number of posts per page, error pages.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('system_site_information_settings'), - 'access arguments' => array('administer site configuration'), - 'file' => 'system.admin.inc', + 'route_name' => 'system_site_information_settings', 'weight' => -20, ); $items['admin/config/system/cron'] = array( 'title' => 'Cron', 'description' => 'Manage automatic site maintenance tasks.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('system_cron_settings'), - 'access arguments' => array('administer site configuration'), - 'file' => 'system.admin.inc', + 'route_name' => 'system_cron_settings', 'weight' => 20, ); // Additional categories diff --git a/core/modules/system/system.routing.yml b/core/modules/system/system.routing.yml index 69a3eaef6bad..b2858440cd54 100644 --- a/core/modules/system/system.routing.yml +++ b/core/modules/system/system.routing.yml @@ -10,3 +10,66 @@ system.machine_name_transliterate: _controller: '\Drupal\system\MachineNameController::transliterate' requirements: _permission: 'access content' + +system_site_information_settings: + pattern: '/admin/config/system/site-information' + defaults: + _form: 'Drupal\system\Form\SiteInformationForm' + requirements: + _permission: 'administer site configuration' + +system_cron_settings: + pattern: '/admin/config/system/cron' + defaults: + _form: 'Drupal\system\Form\CronForm' + requirements: + _permission: 'administer site configuration' + +system_logging_settings: + pattern: '/admin/config/development/logging' + defaults: + _form: 'Drupal\system\Form\LoggingForm' + requirements: + _permission: 'administer site configuration' + +system_performance_settings: + pattern: '/admin/config/development/performance' + defaults: + _form: 'Drupal\system\Form\PerformanceForm' + requirements: + _permission: 'administer site configuration' + +system_file_system_settings: + pattern: '/admin/config/media/file-system' + defaults: + _form: 'Drupal\system\Form\FileSystemForm' + requirements: + _permission: 'administer site configuration' + +system_rss_feeds_settings: + pattern: '/admin/config/services/rss-publishing' + defaults: + _form: 'Drupal\system\Form\RssFeedsForm' + requirements: + _permission: 'administer site configuration' + +system_regional_settings: + pattern: '/admin/config/regional/settings' + defaults: + _form: 'Drupal\system\Form\RegionalForm' + requirements: + _permission: 'administer site configuration' + +system_image_toolkit_settings: + pattern: '/admin/config/media/image-toolkit' + defaults: + _form: 'Drupal\system\Form\ImageToolkitForm' + requirements: + _permission: 'administer administration pages' + +system_site_maintenance_mode: + pattern: '/admin/config/development/maintenance' + defaults: + _form: 'Drupal\system\Form\SiteMaintenanceModeForm' + requirements: + _permission: 'administer site configuration' -- GitLab