Verified Commit 6763cd1d authored by Dave Long's avatar Dave Long
Browse files

fix: #3549583 Use #config_target to remove user_form_system_regional_settings_submit

By: alexpott
By: dcam
(cherry picked from commit d471941b)
parent 1b5f6d95
Loading
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
namespace Drupal\user\Hook;

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\ConfigTarget;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\filter\FilterFormatInterface;
use Drupal\Core\Form\FormStateInterface;
@@ -408,11 +409,10 @@ public function toolbar(): array {
   */
  #[Hook('form_system_regional_settings_alter')]
  public function formSystemRegionalSettingsAlter(&$form, FormStateInterface $form_state) : void {
    $config = \Drupal::config('system.date');
    $form['timezone']['configurable_timezones'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Users may set their own time zone'),
      '#default_value' => $config->get('timezone.user.configurable'),
      '#config_target' => 'system.date:timezone.user.configurable',
    ];
    $form['timezone']['configurable_timezones_wrapper'] = [
      '#type' => 'container',
@@ -429,13 +429,13 @@ public function formSystemRegionalSettingsAlter(&$form, FormStateInterface $form
    $form['timezone']['configurable_timezones_wrapper']['empty_timezone_message'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Remind users at login if their time zone is not set'),
      '#default_value' => $config->get('timezone.user.warn'),
      '#config_target' => 'system.date:timezone.user.warn',
      '#description' => $this->t('Only applied if users may set their own time zone.'),
    ];
    $form['timezone']['configurable_timezones_wrapper']['user_default_timezone'] = [
      '#type' => 'radios',
      '#title' => $this->t('Time zone for new users'),
      '#default_value' => $config->get('timezone.user.default'),
      '#config_target' => new ConfigTarget('system.date', 'timezone.user.default', toConfig: fn($v) => (int) $v),
      '#options' => [
        UserInterface::TIMEZONE_DEFAULT => $this->t('Default time zone'),
        UserInterface::TIMEZONE_EMPTY => $this->t('Empty time zone'),
@@ -443,7 +443,6 @@ public function formSystemRegionalSettingsAlter(&$form, FormStateInterface $form
      ],
      '#description' => $this->t('Only applied if users may set their own time zone.'),
    ];
    $form['#submit'][] = 'user_form_system_regional_settings_submit';
  }

  /**
+0 −12
Original line number Diff line number Diff line
@@ -6,7 +6,6 @@

use Drupal\Component\Utility\Crypt;
use Drupal\Core\Batch\BatchBuilder;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Session\AnonymousUserSession;
use Drupal\Core\Site\Settings;
@@ -712,14 +711,3 @@ function template_preprocess_user(&$variables): void {
  @trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.3.0 and is removed from drupal:12.0.0. Initial template_preprocess functions are registered directly in hook_theme(). See https://www.drupal.org/node/3504125', E_USER_DEPRECATED);
  \Drupal::service(UserThemeHooks::class)->preprocessUser($variables);
}

/**
 * Additional submit handler for \Drupal\system\Form\RegionalForm.
 */
function user_form_system_regional_settings_submit($form, FormStateInterface $form_state): void {
  \Drupal::configFactory()->getEditable('system.date')
    ->set('timezone.user.configurable', $form_state->getValue('configurable_timezones'))
    ->set('timezone.user.warn', $form_state->getValue('empty_timezone_message'))
    ->set('timezone.user.default', $form_state->getValue('user_default_timezone'))
    ->save();
}