diff --git a/core/includes/form.inc b/core/includes/form.inc index bba0000..d4976b9 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -648,13 +648,14 @@ function form_load_include(&$form_state, $type, $module, $name = NULL) { * There is no return value, but you can check to see if there are errors * by calling form_get_errors(). * - * @param $form_id - * The unique string identifying the desired form. If a function - * with that name exists, it is called to build the form array. - * Modules that need to generate the same form (or very similar forms) - * using different $form_ids can implement hook_forms(), which maps - * different $form_id values to the proper form constructor function. Examples - * may be found in node_forms() and search_forms(). + * @param \Drupal\Core\Form\FormInterface|string $form_arg + * A form object to use to build the form, or the unique string identifying + * the desired form. If $form_arg is a string and a function with that + * name exists, it is called to build the form array. Modules that need to + * generate the same form (or very similar forms) using different $form_ids + * can implement hook_forms(), which maps different $form_id values to the + * proper form constructor function. Examples may be found in node_forms() + * and search_forms(). * @param $form_state * A keyed array containing the current state of the form. Most important is * the $form_state['values'] collection, a tree of data used to simulate the @@ -693,7 +694,7 @@ function form_load_include(&$form_state, $type, $module, $name = NULL) { * drupal_form_submit('user_register_form', $form_state); * @endcode */ -function drupal_form_submit($form_id, &$form_state) { +function drupal_form_submit($form_arg, &$form_state) { if (!isset($form_state['build_info']['args'])) { $args = func_get_args(); array_shift($args); @@ -710,6 +711,16 @@ function drupal_form_submit($form_id, &$form_state) { $form_state['input'] = $form_state['values']; $form_state['programmed'] = TRUE; + + // Determine the form ID. + if (is_object($form_arg) && $form_arg instanceof FormInterface) { + $form_state['build_info']['callback_object'] = $form_arg; + $form_id = $form_arg->getFormID(); + } + else { + $form_id = $form_arg; + } + $form = drupal_retrieve_form($form_id, $form_state); // Programmed forms are always submitted. $form_state['submitted'] = TRUE; 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 0000000..4500cd7 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Form/CronForm.php @@ -0,0 +1,122 @@ +configFactory = $config_factory; + $this->state = $key_value_factory->get('state'); + } + + /** + * Returns an instance of this form. + */ + public function getForm() { + return drupal_get_form($this); + } + + /** + * Implements \Drupal\Core\Form\FormInterface::getFormID(). + */ + public function getFormID() { + return 'system_cron_settings'; + } + + /** + * Implements \Drupal\Core\Form\FormInterface::buildForm(). + */ + public function buildForm(array $form, array &$form_state) { + $config = $this->configFactory->get('system.cron'); + + $form['description'] = array( + '#markup' => '

' . t('Cron takes care of running periodic tasks like checking for updates and indexing content for search.') . '

', + ); + $form['run'] = array( + '#type' => 'submit', + '#value' => t('Run cron'), + '#submit' => array(array($this, 'submitCron')), + ); + + $status = '

' . t('Last run: %cron-last ago.', array('%cron-last' => format_interval(REQUEST_TIME - $this->state->get('system.cron_last')))) . '

'; + $form['status'] = array( + '#markup' => $status, + ); + + $form['cron_url'] = array( + '#markup' => '

' . t('To run cron from outside the site, go to !cron', array('!cron' => url('cron/' . $this->state->get('system.cron_key'), array('absolute' => TRUE)))) . '

', + ); + + $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); + } + + /** + * Implements \Drupal\Core\Form\FormInterface::submitForm(). + */ + 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 0000000..50608f1 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Form/FileSystemForm.php @@ -0,0 +1,116 @@ +configFactory = $config_factory; + } + + /** + * Returns an instance of this form. + */ + public function getForm() { + return drupal_get_form($this); + } + + /** + * Implements \Drupal\Core\Form\FormInterface::getFormID(). + */ + public function getFormID() { + return 'system_file_system_settings'; + } + + /** + * Implements \Drupal\Core\Form\FormInterface::buildForm(). + */ + 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 more information about securing private files.', 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); + } + + /** + * Implements \Drupal\Core\Form\FormInterface::submitForm(). + */ + 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/LoggingForm.php b/core/modules/system/lib/Drupal/system/Form/LoggingForm.php new file mode 100644 index 0000000..445bfe3 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Form/LoggingForm.php @@ -0,0 +1,81 @@ +configFactory = $config_factory; + } + + /** + * Returns an instance of this form. + */ + public function getForm() { + return drupal_get_form($this); + } + + /** + * Implements \Drupal\Core\Form\FormInterface::getFormID(). + */ + public function getFormID() { + return 'system_logging_settings'; + } + + /** + * Implements \Drupal\Core\Form\FormInterface::buildForm(). + */ + 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); + } + + /** + * Implements \Drupal\Core\Form\FormInterface::submitForm(). + */ + 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 0000000..1579c4b --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Form/PerformanceForm.php @@ -0,0 +1,159 @@ +configFactory = $config_factory; + } + + /** + * Returns an instance of this form. + */ + public function getForm() { + return drupal_get_form($this); + } + + /** + * Implements \Drupal\Core\Form\FormInterface::getFormID(). + */ + public function getFormID() { + return 'system_performance_settings'; + } + + /** + * Implements \Drupal\Core\Form\FormInterface::buildForm(). + */ + public function buildForm(array $form, array &$form_state) { + drupal_add_library('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'), + ); + + $form['caching']['cache'] = array( + '#type' => 'checkbox', + '#title' => t('Cache pages for anonymous users'), + '#default_value' => $config->get('cache.page.enabled'), + '#weight' => -2, + ); + + $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('Expiration of cached pages'), + '#default_value' => $config->get('cache.page.max_age'), + '#options' => $period, + '#description' => t('The maximum time an external cache can use an old version of a page.'), + ); + + $directory = 'public://'; + $is_writable = is_dir($directory) && is_writable($directory); + $disabled = !$is_writable; + $disabled_message = ''; + if (!$is_writable) { + $disabled_message = ' ' . t('Set up the public files directory to make these optimizations available.', 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.enabled') ? '' : ' 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 and compress 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); + } + + /** + * Implements \Drupal\Core\Form\FormInterface::submitForm(). + */ + public function submitForm(array &$form, array &$form_state) { + $this->configFactory->get('system.performance') + ->set('cache.page.enabled', $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(); + + // This form allows page compression settings to be changed, which can + // invalidate the page cache, so it needs to be cleared on form submit. + cache('page')->deleteAll(); + drupal_clear_css_cache(); + drupal_clear_js_cache(); + + 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 0000000..18c50e3 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Form/RegionalForm.php @@ -0,0 +1,150 @@ +configFactory = $config_factory; + } + + /** + * Returns an instance of this form. + */ + public function getForm() { + return drupal_get_form($this); + } + + /** + * Implements \Drupal\Core\Form\FormInterface::getFormID(). + */ + public function getFormID() { + return 'system_regional_settings'; + } + + /** + * Implements \Drupal\Core\Form\FormInterface::buildForm(). + */ + 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); + } + + /** + * Implements \Drupal\Core\Form\FormInterface::submitForm(). + */ + 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 0000000..be43639 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Form/RssFeedsForm.php @@ -0,0 +1,95 @@ +configFactory = $config_factory; + } + + /** + * Returns an instance of this form. + */ + public function getForm() { + return drupal_get_form($this); + } + + /** + * Implements \Drupal\Core\Form\FormInterface::getFormID(). + */ + public function getFormID() { + return 'system_rss_feeds_settings'; + } + + /** + * Implements \Drupal\Core\Form\FormInterface::buildForm(). + */ + 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); + } + + /** + * Implements \Drupal\Core\Form\FormInterface::submitForm(). + */ + 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 0000000..0382a71 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Form/SiteInformationForm.php @@ -0,0 +1,171 @@ +configFactory = $config_factory; + } + + /** + * Returns an instance of this form. + */ + public function getForm() { + return drupal_get_form($this); + } + + /** + * Implements \Drupal\Core\Form\FormInterface::getFormID(). + */ + public function getFormID() { + return 'system_site_information_settings'; + } + + /** + * Implements \Drupal\Core\Form\FormInterface::buildForm(). + */ + 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 From 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)), + ); + + return parent::buildForm($form, $form_state); + } + + /** + * Implements \Drupal\Core\Form\FormInterface::validateForm(). + */ + 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'], 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']))); + } + + parent::validateForm($form, $form_state); + } + + /** + * Implements \Drupal\Core\Form\FormInterface::submitForm(). + */ + 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 0000000..6f7fc5f --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Form/SiteMaintenanceModeForm.php @@ -0,0 +1,81 @@ +configFactory = $config_factory; + } + + /** + * Returns an instance of this form. + */ + public function getForm() { + return drupal_get_form($this); + } + + /** + * Implements \Drupal\Core\Form\FormInterface::getFormID(). + */ + public function getFormID() { + return 'system_site_maintenance_mode'; + } + + /** + * Implements \Drupal\Core\Form\FormInterface::buildForm(). + */ + 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" permission will be able to access the site. Authorized users can log in directly via the user login 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); + } + + /** + * Implements \Drupal\Core\Form\FormInterface::submitForm(). + */ + 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/lib/Drupal/system/SystemBundle.php b/core/modules/system/lib/Drupal/system/SystemBundle.php index 8662169..7dcd452 100644 --- a/core/modules/system/lib/Drupal/system/SystemBundle.php +++ b/core/modules/system/lib/Drupal/system/SystemBundle.php @@ -8,6 +8,7 @@ namespace Drupal\system; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpKernel\Bundle\Bundle; /** @@ -25,5 +26,23 @@ public function build(ContainerBuilder $container) { // Register the various system plugin manager classes with the dependency // injection container. $container->register('plugin.manager.system.plugin_ui', 'Drupal\system\Plugin\Type\PluginUIManager'); + + $container->register('system.form.site_information', 'Drupal\system\Form\SiteInformationForm') + ->addArgument(new Reference('config.factory')); + $container->register('system.form.cron', 'Drupal\system\Form\CronForm') + ->addArgument(new Reference('config.factory')) + ->addArgument(new Reference('keyvalue')); + $container->register('system.form.logging', 'Drupal\system\Form\LoggingForm') + ->addArgument(new Reference('config.factory')); + $container->register('system.form.performance', 'Drupal\system\Form\PerformanceForm') + ->addArgument(new Reference('config.factory')); + $container->register('system.form.file_system', 'Drupal\system\Form\FileSystemForm') + ->addArgument(new Reference('config.factory')); + $container->register('system.form.rss_feeds', 'Drupal\system\Form\RssFeedsForm') + ->addArgument(new Reference('config.factory')); + $container->register('system.form.regional', 'Drupal\system\Form\RegionalForm') + ->addArgument(new Reference('config.factory')); + $container->register('system.form.site_maintenance_mode', 'Drupal\system\Form\SiteMaintenanceModeForm') + ->addArgument(new Reference('config.factory')); } } diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestObject.php b/core/modules/system/lib/Drupal/system/SystemConfigFormBase.php similarity index 50% copy from core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestObject.php copy to core/modules/system/lib/Drupal/system/SystemConfigFormBase.php index f08d88e..b415a70 100644 --- a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestObject.php +++ b/core/modules/system/lib/Drupal/system/SystemConfigFormBase.php @@ -2,36 +2,32 @@ /** * @file - * Contains \Drupal\form_test\FormTestObject. + * Contains \Drupal\system\SystemConfigFormBase. */ -namespace Drupal\form_test; +namespace Drupal\system; use Drupal\Core\Form\FormInterface; /** - * Provides a test form object. + * Base class for implementing system configuration forms. */ -class FormTestObject implements FormInterface { - - /** - * Implements \Drupal\Core\Form\FormInterface::getFormID(). - */ - public function getFormID() { - return 'form_test_form_test_object'; - } +abstract class SystemConfigFormBase implements FormInterface { /** * Implements \Drupal\Core\Form\FormInterface::buildForm(). */ public function buildForm(array $form, array &$form_state) { - $form['element'] = array('#markup' => 'The FormTestObject::buildForm() method was used for this form.'); - $form['actions']['#type'] = 'actions'; $form['actions']['submit'] = array( '#type' => 'submit', - '#value' => t('Save'), + '#value' => t('Save configuration'), + '#button_type' => 'primary', ); + + // By default, render the form using theme_system_settings_form(). + $form['#theme'] = 'system_settings_form'; + return $form; } @@ -39,14 +35,13 @@ public function buildForm(array $form, array &$form_state) { * Implements \Drupal\Core\Form\FormInterface::validateForm(). */ public function validateForm(array &$form, array &$form_state) { - drupal_set_message(t('The FormTestObject::validateForm() method was used for this form.')); } /** * Implements \Drupal\Core\Form\FormInterface::submitForm(). */ public function submitForm(array &$form, array &$form_state) { - drupal_set_message(t('The FormTestObject::submitForm() method was used for this form.')); + drupal_set_message(t('The configuration options have been saved.')); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Form/FormObjectTest.php b/core/modules/system/lib/Drupal/system/Tests/Form/FormObjectTest.php index c35a443..cf2fe24 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Form/FormObjectTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Form/FormObjectTest.php @@ -7,12 +7,13 @@ namespace Drupal\system\Tests\Form; -use Drupal\simpletest\WebTestBase; +use Drupal\system\Tests\System\SystemConfigFormBase; +use Drupal\form_test\FormTestObject; /** * Tests building a form from an object. */ -class FormObjectTest extends WebTestBase { +class FormObjectTest extends SystemConfigFormBase { /** * Modules to enable. @@ -29,6 +30,19 @@ public static function getInfo() { ); } + protected function setUp() { + parent::setUp(); + + $this->form_id = new FormTestObject(); + $this->values = array( + 'bananas' => array( + '#value' => $this->randomString(10), + '#config_name' => 'form_test.object', + '#config_key' => 'bananas', + ), + ); + } + /** * Tests using an object as the form callback. */ diff --git a/core/modules/system/lib/Drupal/system/Tests/Form/SystemConfigFormTest.php b/core/modules/system/lib/Drupal/system/Tests/Form/SystemConfigFormTest.php new file mode 100644 index 0000000..7245448 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Form/SystemConfigFormTest.php @@ -0,0 +1,44 @@ + 'SystemConfigmForm tests', + 'description' => 'Tests the SystemConfigFormBase class.', + 'group' => 'Form API', + ); + } + + /** + * Tests the SystemConfigFormBase class. + */ + function testSystemConfigForm() { + $this->drupalGet('form-test/system-config-form'); + $element = $this->xpath('//div[@id = :id]/input[contains(@class, :class)]', array(':id' => 'edit-actions', ':class' => 'button-primary')); + $this->assertTrue($element, 'The primary action submit button was found.'); + $this->drupalPost(NULL, array(), t('Save configuration')); + $this->assertText(t('The configuration options have been saved.')); + } + +} diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index b483e7e..d54fe9d 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -1397,425 +1397,6 @@ function system_modules_uninstall_submit($form, &$form_state) { } /** - * Form builder; The general site information form. - * - * @ingroup forms - * @see system_settings_form() - */ -function system_site_information_settings($form, &$form_state) { - $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 From 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('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) { - $form['description'] = array( - '#markup' => '

' . t('Cron takes care of running periodic tasks like checking for updates and indexing content for search.') . '

', - ); - $form['run'] = array( - '#type' => 'submit', - '#value' => t('Run cron'), - '#submit' => array('system_run_cron_submit'), - ); - - $status = '

' . t('Last run: %cron-last ago.', array('%cron-last' => format_interval(REQUEST_TIME - state()->get('system.cron_last')))) . '

'; - $form['status'] = array( - '#markup' => $status, - ); - - $form['cron_url'] = array( - '#markup' => '

' . t('To run cron from outside the site, go to !cron', array('!cron' => url('cron/' . state()->get('system.cron_key'), array('absolute' => TRUE)))) . '

', - ); - - $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('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) { - $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('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 = 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'), - ); - - $form['caching']['cache'] = array( - '#type' => 'checkbox', - '#title' => t('Cache pages for anonymous users'), - '#default_value' => $config->get('cache.page.enabled'), - '#weight' => -2, - ); - - $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('Expiration of cached pages'), - '#default_value' => $config->get('cache.page.max_age'), - '#options' => $period, - '#description' => t('The maximum time an external cache can use an old version of a page.'), - ); - - $directory = 'public://'; - $is_writable = is_dir($directory) && is_writable($directory); - $disabled = !$is_writable; - $disabled_message = ''; - if (!$is_writable) { - $disabled_message = ' ' . t('Set up the public files directory to make these optimizations available.', 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.enabled') ? '' : ' 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 and compress 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 = config('system.performance'); - $config->set('cache.page.enabled', $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_settings_form_sumbit() - */ -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 more information about securing private files.', 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 @@ -1855,195 +1436,6 @@ function system_image_toolkit_settings() { } /** - * Form builder; Configure how the site handles RSS feeds. - * - * @ingroup forms - */ -function system_rss_feeds_settings($form, &$form_state) { - $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('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 = 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" permission will be able to access the site. Authorized users can log in directly via the user login 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('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. * * @param $check diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 1a659c5..99b40e9 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -799,11 +799,9 @@ 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'), + 'page callback' => 'NOT_USED', 'access arguments' => array('administer site configuration'), 'weight' => -10, - 'file' => 'system.admin.inc', ); $items['admin/config/media/image-toolkit'] = array( 'title' => 'Image toolkit', @@ -828,10 +826,8 @@ 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'), + 'page callback' => 'NOT_USED', 'access arguments' => array('administer site configuration'), - 'file' => 'system.admin.inc', ); // Development settings. @@ -847,28 +843,22 @@ 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'), + 'page callback' => 'NOT_USED', 'access arguments' => array('administer site configuration'), - 'file' => 'system.admin.inc', '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'), + 'page callback' => 'NOT_USED', 'access arguments' => array('administer site configuration'), - 'file' => 'system.admin.inc', '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'), + 'page callback' => 'NOT_USED', 'access arguments' => array('administer site configuration'), - 'file' => 'system.admin.inc', 'weight' => -15, ); @@ -885,11 +875,9 @@ 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'), + 'page callback' => 'NOT_USED', 'access arguments' => array('administer site configuration'), 'weight' => -20, - 'file' => 'system.admin.inc', ); $items['admin/config/regional/date-time'] = array( 'title' => 'Formats', @@ -957,19 +945,15 @@ 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'), + 'page callback' => 'NOT_USED', 'access arguments' => array('administer site configuration'), - 'file' => 'system.admin.inc', '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'), + 'page callback' => 'NOT_USED', 'access arguments' => array('administer site configuration'), - 'file' => 'system.admin.inc', 'weight' => 20, ); // Additional categories diff --git a/core/modules/system/system.routing.yml b/core/modules/system/system.routing.yml index 085895e..b02b284 100644 --- a/core/modules/system/system.routing.yml +++ b/core/modules/system/system.routing.yml @@ -4,3 +4,59 @@ system.cron: _controller: '\Drupal\system\CronController::run' requirements: _access_system_cron: 'TRUE' + +system_site_information_settings: + pattern: '/admin/config/system/site-information' + defaults: + _controller: 'system.form.site_information:getForm' + requirements: + _permission: 'administer site configuration' + +system_cron_settings: + pattern: '/admin/config/system/cron' + defaults: + _controller: 'system.form.cron:getForm' + requirements: + _permission: 'administer site configuration' + +system_logging_settings: + pattern: '/admin/config/development/logging' + defaults: + _controller: 'system.form.logging:getForm' + requirements: + _permission: 'administer site configuration' + +system_performance_settings: + pattern: '/admin/config/development/performance' + defaults: + _controller: 'system.form.performance:getForm' + requirements: + _permission: 'administer site configuration' + +system_file_system_settings: + pattern: '/admin/config/media/file-system' + defaults: + _controller: 'system.form.file_system:getForm' + requirements: + _permission: 'administer site configuration' + +system_rss_feeds_settings: + pattern: '/admin/config/services/rss-publishing' + defaults: + _controller: 'system.form.rss_feeds:getForm' + requirements: + _permission: 'administer site configuration' + +system_regional_settings: + pattern: '/admin/config/regional/settings' + defaults: + _controller: 'system.form.regional:getForm' + requirements: + _permission: 'administer site configuration' + +system_site_maintenance_mode: + pattern: '/admin/config/development/maintenance' + defaults: + _controller: 'system.form.site_maintenance_mode:getForm' + requirements: + _permission: 'administer site configuration' diff --git a/core/modules/system/tests/modules/form_test/form_test.module b/core/modules/system/tests/modules/form_test/form_test.module index f85fd6d..fe5d999 100644 --- a/core/modules/system/tests/modules/form_test/form_test.module +++ b/core/modules/system/tests/modules/form_test/form_test.module @@ -7,6 +7,7 @@ use Drupal\form_test\Callbacks; use Drupal\form_test\FormTestObject; +use Drupal\form_test\SystemConfigFormTestForm; use Drupal\Core\Datetime\DrupalDateTime; /** @@ -33,6 +34,12 @@ function form_test_menu() { 'access callback' => TRUE, 'type' => MENU_CALLBACK, ); + $items['form-test/system-config-form'] = array( + 'title' => 'Form object builder test', + 'page callback' => 'form_test_system_config_form', + 'access callback' => TRUE, + 'type' => MENU_CALLBACK, + ); $items['form-test/validate-required'] = array( 'title' => 'Form #required validation', 'page callback' => 'drupal_get_form', @@ -377,6 +384,13 @@ function form_test_object_builder() { } /** + * Page callback: Displays a form built from SystemConfigForm. + */ +function form_test_system_config_form() { + return drupal_get_form(new SystemConfigFormTestForm()); +} + +/** * Form submit handler to return form values as JSON. */ function _form_test_submit_values_json($form, &$form_state) { diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestObject.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestObject.php index f08d88e..22b6d7a 100644 --- a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestObject.php +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestObject.php @@ -27,6 +27,11 @@ public function getFormID() { public function buildForm(array $form, array &$form_state) { $form['element'] = array('#markup' => 'The FormTestObject::buildForm() method was used for this form.'); + $form['bananas'] = array( + '#type' => 'textfield', + '#title' => t('Bananas'), + ); + $form['actions']['#type'] = 'actions'; $form['actions']['submit'] = array( '#type' => 'submit', @@ -47,6 +52,9 @@ public function validateForm(array &$form, array &$form_state) { */ public function submitForm(array &$form, array &$form_state) { drupal_set_message(t('The FormTestObject::submitForm() method was used for this form.')); + config('form_test.object') + ->set('bananas', $form_state['values']['bananas']) + ->save(); } } diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/SystemConfigFormTestForm.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/SystemConfigFormTestForm.php new file mode 100644 index 0000000..26c1c0e --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/SystemConfigFormTestForm.php @@ -0,0 +1,24 @@ + 'details', '#title' => t('Caching'), @@ -75,7 +77,7 @@ public function buildForm(array $form, array &$form_state) { ); } - return system_config_form($form, $form_state); + return $form; } /** diff --git a/core/modules/views/views_ui/lib/Drupal/views_ui/Form/BasicSettingsForm.php b/core/modules/views/views_ui/lib/Drupal/views_ui/Form/BasicSettingsForm.php index 8617ebc..082eaa3 100644 --- a/core/modules/views/views_ui/lib/Drupal/views_ui/Form/BasicSettingsForm.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/Form/BasicSettingsForm.php @@ -23,6 +23,8 @@ public function getFormID() { * Implements \Drupal\Core\Form\FormInterface::buildForm(). */ public function buildForm(array $form, array &$form_state) { + $form = parent::buildForm($form, $form_state); + $options = array(); foreach (list_themes() as $name => $theme) { if ($theme->status) { @@ -115,7 +117,7 @@ public function buildForm(array $form, array &$form_state) { '#default_value' => $this->config->get('ui.show.additional_queries'), ); - return system_config_form($form, $form_state); + return $form; } /** diff --git a/core/modules/views/views_ui/lib/Drupal/views_ui/Form/SettingsFormBase.php b/core/modules/views/views_ui/lib/Drupal/views_ui/Form/SettingsFormBase.php index 173d5ec..fba4fa1 100644 --- a/core/modules/views/views_ui/lib/Drupal/views_ui/Form/SettingsFormBase.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/Form/SettingsFormBase.php @@ -7,13 +7,13 @@ namespace Drupal\views_ui\Form; -use Drupal\Core\Form\FormInterface; use Drupal\Core\Config\ConfigFactory; +use Drupal\system\SystemConfigFormBase; /** * Form builder for the advanced admin settings page. */ -abstract class SettingsFormBase implements FormInterface { +abstract class SettingsFormBase extends SystemConfigFormBase { /** * Stores the views configuration. @@ -42,10 +42,4 @@ public function getForm() { return drupal_get_form($this); } - /** - * Implements \Drupal\Core\Form\FormInterface::validateForm(). - */ - public function validateForm(array &$form, array &$form_state) { - } - }