diff --git a/core/modules/contact/src/Form/UserAccountSettingsFormAlter.php b/core/modules/contact/src/Form/UserAccountSettingsFormAlter.php index 8eb9d3b..32538df 100644 --- a/core/modules/contact/src/Form/UserAccountSettingsFormAlter.php +++ b/core/modules/contact/src/Form/UserAccountSettingsFormAlter.php @@ -13,6 +13,7 @@ use Drupal\Core\Form\ConfigFormBaseTrait; use Drupal\Core\Form\FormAlterInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -23,6 +24,7 @@ class UserAccountSettingsFormAlter implements FormAlterInterface, ContainerInjectionInterface { use ConfigFormBaseTrait; use DependencySerializationTrait; + use StringTranslationTrait; /** * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory @@ -54,14 +56,14 @@ protected function getEditableConfigNames() { public function alter(array &$form, FormStateInterface $form_state) { $form['contact'] = array( '#type' => 'details', - '#title' => t('Contact settings'), + '#title' => $this->t('Contact settings'), '#open' => TRUE, '#weight' => 0, ); $form['contact']['contact_default_status'] = array( '#type' => 'checkbox', - '#title' => t('Enable the personal contact form by default for new users'), - '#description' => t('Changing this setting will not affect existing users.'), + '#title' => $this->t('Enable the personal contact form by default for new users'), + '#description' => $this->t('Changing this setting will not affect existing users.'), // @see \Drupal\Core\Form\ConfigFormBase::config() '#default_value' => $this->config('contact.settings')->get('user_default_enabled'), ); diff --git a/core/modules/contact/src/Form/UserFormAlter.php b/core/modules/contact/src/Form/UserFormAlter.php index 837bb52..231bd55 100644 --- a/core/modules/contact/src/Form/UserFormAlter.php +++ b/core/modules/contact/src/Form/UserFormAlter.php @@ -13,6 +13,7 @@ use Drupal\Core\Form\FormAlterInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Session\AccountProxyInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\user\UserDataInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -23,6 +24,7 @@ */ class UserFormAlter implements FormAlterInterface, ContainerInjectionInterface { use DependencySerializationTrait; + use StringTranslationTrait; /** * @param \Drupal\Core\Session\AccountProxyInterface $current_user @@ -55,7 +57,7 @@ public static function create(ContainerInterface $container) { public function alter(array &$form, FormStateInterface $form_state) { $form['contact'] = array( '#type' => 'details', - '#title' => t('Contact settings'), + '#title' => $this->t('Contact settings'), '#open' => TRUE, '#weight' => 5, ); @@ -65,9 +67,9 @@ public function alter(array &$form, FormStateInterface $form_state) { } $form['contact']['contact'] = array( '#type' => 'checkbox', - '#title' => t('Personal contact form'), + '#title' => $this->t('Personal contact form'), '#default_value' => isset($account_data) ? $account_data : $this->configFactory->get('contact.settings')->get('user_default_enabled'), - '#description' => t('Allow other users to contact you via a personal contact form which keeps your email address hidden. Note that some privileged users such as site administrators are still able to contact you even if you choose to disable this feature.'), + '#description' => $this->t('Allow other users to contact you via a personal contact form which keeps your email address hidden. Note that some privileged users such as site administrators are still able to contact you even if you choose to disable this feature.'), ); } diff --git a/core/modules/dblog/src/Form/SystemLoggingSettingsFormAlter.php b/core/modules/dblog/src/Form/SystemLoggingSettingsFormAlter.php index 1af5242..2d5a48f 100644 --- a/core/modules/dblog/src/Form/SystemLoggingSettingsFormAlter.php +++ b/core/modules/dblog/src/Form/SystemLoggingSettingsFormAlter.php @@ -13,11 +13,25 @@ use Drupal\Core\Form\ConfigFormBaseTrait; use Drupal\Core\Form\FormAlterInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Routing\UrlGeneratorTrait; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Symfony\Component\DependencyInjection\ContainerInterface; +/** + * Alters the logging form to add dblog settings. + * + * @see \Drupal\system\Form\LoggingForm + */ class SystemLoggingSettingsFormAlter implements FormAlterInterface, ContainerInjectionInterface { use ConfigFormBaseTrait; use DependencySerializationTrait; + use StringTranslationTrait; + use UrlGeneratorTrait; + + /** + * @var \Drupal\Core\Config\ConfigFactoryInterface + */ + protected $configFactory; /** * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory @@ -50,10 +64,10 @@ public function alter(array &$form, FormStateInterface $form_state) { $row_limits = array(100, 1000, 10000, 100000, 1000000); $form['dblog_row_limit'] = array( '#type' => 'select', - '#title' => t('Database log messages to keep'), + '#title' => $this->t('Database log messages to keep'), '#default_value' => $this->config('dblog.settings')->get('row_limit'), - '#options' => array(0 => t('All')) + array_combine($row_limits, $row_limits), - '#description' => t('The maximum number of messages to keep in the database log. Requires a cron maintenance task.', array('@cron' => \Drupal::url('system.status'))) + '#options' => array(0 => $this->t('All')) + array_combine($row_limits, $row_limits), + '#description' => $this->t('The maximum number of messages to keep in the database log. Requires a cron maintenance task.', array('@cron' => $this->url('system.status'))) ); } diff --git a/core/modules/language/src/Form/ContentLanguageSettingsForm.php b/core/modules/language/src/Form/ContentLanguageSettingsForm.php index a7151fe..26e7ef5 100644 --- a/core/modules/language/src/Form/ContentLanguageSettingsForm.php +++ b/core/modules/language/src/Form/ContentLanguageSettingsForm.php @@ -130,7 +130,15 @@ public function buildForm(array $form, FormStateInterface $form_state) { } } - $form = parent::buildForm($form, $form_state); + $form['actions']['#type'] = 'actions'; + $form['actions']['submit'] = array( + '#type' => 'submit', + '#value' => $this->t('Save configuration'), + '#button_type' => 'primary', + ); + + // By default, render the form using theme_system_config_form(). + $form['#theme'] = 'system_config_form'; return $form; } diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 4ee3790..6f1dc88 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -833,62 +833,15 @@ function node_page_top(array &$page) { /** * Implements hook_form_FORM_ID_alter(). * - * Alters the System module's site information settings form to add a global - * default setting for number of posts to show on node listing pages. - * - * @see node_page_default() - * @see node_form_system_site_information_settings_form_submit() - */ -function node_form_system_site_information_settings_form_alter(&$form, FormStateInterface $form_state, $form_id) { - $options = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30); - $form['front_page']['default_nodes_main'] = array( - '#type' => 'select', - '#title' => t('Number of posts on front page'), - '#default_value' => \Drupal::config('node.settings')->get('items_per_page'), - '#options' => array_combine($options, $options), - '#access' => (\Drupal::config('system.site')->get('page.front') == 'node'), - '#description' => t('The maximum number of posts displayed on overview pages such as the front page.'), - ); - $form['#submit'][] = 'node_form_system_site_information_settings_form_submit'; -} - -/** - * Form submission handler for system_site_information_settings(). - * - * @see node_form_system_site_information_settings_form_alter() - */ -function node_form_system_site_information_settings_form_submit($form, FormStateInterface $form_state) { - \Drupal::config('node.settings') - ->set('items_per_page', $form_state->getValue('default_nodes_main')) - ->save(); -} - -/** - * Implements hook_form_FORM_ID_alter(). - * * Alters the theme form to use the admin theme on node editing. * - * @see node_form_system_themes_admin_form_submit() - */ -function node_form_system_themes_admin_form_alter(&$form, FormStateInterface $form_state, $form_id) { - $form['admin_theme']['use_admin_theme'] = array( - '#type' => 'checkbox', - '#title' => t('Use the administration theme when editing or creating content'), - '#default_value' => $form_state->getFormObject()->config('node.settings')->get('use_admin_theme'), - ); - $form['#submit'][] = 'node_form_system_themes_admin_form_submit'; -} - -/** - * Form submission handler for system_themes_admin_form(). - * - * @see node_form_system_themes_admin_form_alter() + * @see \Drupal\system\Form\ThemeAdminForm */ -function node_form_system_themes_admin_form_submit($form, FormStateInterface $form_state) { - $form_state->getFormObject()->config('node.settings') - ->set('use_admin_theme', $form_state->getValue('use_admin_theme')) - ->save(); - \Drupal::service('router.builder_indicator')->setRebuildNeeded(); +function node_form_system_themes_admin_form_alter(&$form, FormStateInterface $form_state) { + /** @var \Drupal\node\Form\SystemThemesAdminFormAlter $alter */ + $alter = \Drupal::resolve('Drupal\node\Form\SystemThemesAdminFormAlter'); + $alter->alter($form, $form_state); + $form['#submit'][] = array($alter, 'submit'); } /** diff --git a/core/modules/node/src/Form/SystemThemesAdminFormAlter.php b/core/modules/node/src/Form/SystemThemesAdminFormAlter.php new file mode 100644 index 0000000..170824f --- /dev/null +++ b/core/modules/node/src/Form/SystemThemesAdminFormAlter.php @@ -0,0 +1,102 @@ +configFactory = $config_factory; + $this->routeBuilderIndicator = $indicator; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('config.factory'), + $container->get('router.builder_indicator') + ); + } + + /** + * {@inheritdoc} + */ + protected function getEditableConfigNames() { + return ['node.settings']; + } + + /** + * {@inheritdoc} + */ + public function alter(array &$form, FormStateInterface $form_state) { + $form['admin_theme']['use_admin_theme'] = array( + '#type' => 'checkbox', + '#title' => $this->t('Use the administration theme when editing or creating content'), + '#default_value' => $this->config('node.settings')->get('use_admin_theme'), + ); + } + + /** + * {@inheritdoc} + */ + public function validate(array &$form, FormStateInterface $form_state) { + // No validations to perform. + } + + /** + * {@inheritdoc} + */ + public function submit(array &$form, FormStateInterface $form_state) { + $this->config('node.settings') + ->set('use_admin_theme', $form_state->getValue('use_admin_theme')) + ->save(); + $this->routeBuilderIndicator->setRebuildNeeded(); + } + +} diff --git a/core/modules/syslog/src/Form/SystemLoggingSettingsFormAlter.php b/core/modules/syslog/src/Form/SystemLoggingSettingsFormAlter.php new file mode 100644 index 0000000..4609b19 --- /dev/null +++ b/core/modules/syslog/src/Form/SystemLoggingSettingsFormAlter.php @@ -0,0 +1,143 @@ +configFactory = $config_factory; + $this->moduleHandler = $module_handler; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('config.factory'), + $container->get('module_handler') + ); + } + + /** + * {@inheritdoc} + */ + protected function getEditableConfigNames() { + return ['syslog.settings']; + } + + /** + * {@inheritdoc} + */ + public function alter(array &$form, FormStateInterface $form_state) { + $config = $this->config('syslog.settings'); + $help = $this->moduleHandler->moduleExists('help') ? ' ' . $this->l($this->t('More information'), new Url('help.page', ['name' => 'syslog'])) . '.' : NULL; + $form['syslog_identity'] = array( + '#type' => 'textfield', + '#title' => $this->t('Syslog identity'), + '#default_value' => $config->get('identity'), + '#description' => $this->t('A string that will be prepended to every message logged to Syslog. If you have multiple sites logging to the same Syslog log file, a unique identity per site makes it easy to tell the log entries apart.') . $help, + ); + if (defined('LOG_LOCAL0')) { + $form['syslog_facility'] = array( + '#type' => 'select', + '#title' => $this->t('Syslog facility'), + '#default_value' => $config->get('facility'), + '#options' => $this->facilityList(), + '#description' => $this->t('Depending on the system configuration, Syslog and other logging tools use this code to identify or filter messages from within the entire system log.') . $help, + ); + } + $form['syslog_format'] = array( + '#type' => 'textarea', + '#title' => $this->t('Syslog format'), + '#default_value' => $config->get('format'), + '#description' => $this->t('Specify the format of the syslog entry. Available variables are:
!base_url
Base URL of the site.
!timestamp
Unix timestamp of the log entry.
!type
The category to which this message belongs.
!ip
IP address of the user triggering the message.
!request_uri
The requested URI.
!referer
HTTP Referer if available.
!uid
User ID.
!link
A link to associate with the message.
!message
The message to store in the log.
'), + ); + } + + /** + * Lists all possible syslog facilities for UNIX/Linux. + * + * @return array + * An array of syslog facilities for UNIX/Linux. + */ + protected function facilityList() { + return array( + LOG_LOCAL0 => 'LOG_LOCAL0', + LOG_LOCAL1 => 'LOG_LOCAL1', + LOG_LOCAL2 => 'LOG_LOCAL2', + LOG_LOCAL3 => 'LOG_LOCAL3', + LOG_LOCAL4 => 'LOG_LOCAL4', + LOG_LOCAL5 => 'LOG_LOCAL5', + LOG_LOCAL6 => 'LOG_LOCAL6', + LOG_LOCAL7 => 'LOG_LOCAL7', + ); + } + + /** + * {@inheritdoc} + */ + public function validate(array &$form, FormStateInterface $form_state) { + // No validations to perform. + } + + /** + * {@inheritdoc} + */ + public function submit(array &$form, FormStateInterface $form_state) { + $this->config('syslog.settings') + ->set('identity', $form_state->getValue('syslog_identity')) + ->set('facility', $form_state->getValue('syslog_facility')) + ->set('format', $form_state->getValue('syslog_format')) + ->save(); + } + +} diff --git a/core/modules/syslog/syslog.module b/core/modules/syslog/syslog.module index bb6ef17..ad3ed1b 100644 --- a/core/modules/syslog/syslog.module +++ b/core/modules/syslog/syslog.module @@ -5,7 +5,6 @@ * Redirects logging messages to syslog. */ -use Drupal\Core\Url; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\RouteMatchInterface; @@ -33,61 +32,8 @@ function syslog_help($route_name, RouteMatchInterface $route_match) { * Implements hook_form_FORM_ID_alter(). */ function syslog_form_system_logging_settings_alter(&$form, FormStateInterface $form_state) { - $config = $form_state->getFormObject()->config('syslog.settings'); - $help = \Drupal::moduleHandler()->moduleExists('help') ? ' ' . \Drupal::l(t('More information'), new Url('help.page', ['name' => 'syslog'])) . '.' : NULL; - $form['syslog_identity'] = array( - '#type' => 'textfield', - '#title' => t('Syslog identity'), - '#default_value' => $config->get('identity'), - '#description' => t('A string that will be prepended to every message logged to Syslog. If you have multiple sites logging to the same Syslog log file, a unique identity per site makes it easy to tell the log entries apart.') . $help, - ); - if (defined('LOG_LOCAL0')) { - $form['syslog_facility'] = array( - '#type' => 'select', - '#title' => t('Syslog facility'), - '#default_value' => $config->get('facility'), - '#options' => syslog_facility_list(), - '#description' => t('Depending on the system configuration, Syslog and other logging tools use this code to identify or filter messages from within the entire system log.') . $help, - ); - } - $form['syslog_format'] = array( - '#type' => 'textarea', - '#title' => t('Syslog format'), - '#default_value' => $config->get('format'), - '#description' => t('Specify the format of the syslog entry. Available variables are:
!base_url
Base URL of the site.
!timestamp
Unix timestamp of the log entry.
!type
The category to which this message belongs.
!ip
IP address of the user triggering the message.
!request_uri
The requested URI.
!referer
HTTP Referer if available.
!uid
User ID.
!link
A link to associate with the message.
!message
The message to store in the log.
'), - ); - - $form['#submit'][] = 'syslog_logging_settings_submit'; -} - -/** - * Form submission handler for system_logging_settings(). - * - * @see syslog_form_system_logging_settings_alter() - */ -function syslog_logging_settings_submit($form, FormStateInterface $form_state) { - $form_state->getFormObject()->config('syslog.settings') - ->set('identity', $form_state->getValue('syslog_identity')) - ->set('facility', $form_state->getValue('syslog_facility')) - ->set('format', $form_state->getValue('syslog_format')) - ->save(); -} - -/** - * Lists all possible syslog facilities for UNIX/Linux. - * - * @return array - * An array of syslog facilities for UNIX/Linux. - */ -function syslog_facility_list() { - return array( - LOG_LOCAL0 => 'LOG_LOCAL0', - LOG_LOCAL1 => 'LOG_LOCAL1', - LOG_LOCAL2 => 'LOG_LOCAL2', - LOG_LOCAL3 => 'LOG_LOCAL3', - LOG_LOCAL4 => 'LOG_LOCAL4', - LOG_LOCAL5 => 'LOG_LOCAL5', - LOG_LOCAL6 => 'LOG_LOCAL6', - LOG_LOCAL7 => 'LOG_LOCAL7', - ); + /** @var \Drupal\syslog\Form\SystemLoggingSettingsFormAlter $alter */ + $alter = \Drupal::resolve('Drupal\syslog\Form\SystemLoggingSettingsFormAlter'); + $alter->alter($form, $form_state); + $form['#submit'][] = array($alter, 'submit'); }