Commit e88f0ab7 authored by catch's avatar catch

Issue #1925660 by ACF, tim.plunkett, mtift, heddn, Cottser: Convert system's...

Issue #1925660 by ACF, tim.plunkett, mtift, heddn, Cottser: Convert system's system_config_form() to SystemConfigFormBase.
parent 261b71d2
<?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)));
}
}
<?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);
}
}
<?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);
}
}
<?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);
}
}
<?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.'));
}
}
<?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);
}
}
<?php
/**
* @file
* Contains \Drupal\system\Form\RssFeedsForm.
*/
namespace Drupal\system\Form;
use Drupal\system\SystemConfigFormBase;
/**
* Configure RSS settings for this site.
*/