setDefaultTimeZone example



  /** * Updates the default time zone when time zone config changes. * * @param \Drupal\Core\Config\ConfigCrudEvent $event * The config crud event. */
  public function onConfigSave(ConfigCrudEvent $event) {
    $saved_config = $event->getConfig();
    if ($saved_config->getName() === 'system.date' && ($event->isChanged('timezone.default') || $event->isChanged('timezone.user.configurable'))) {
      $this->setDefaultTimeZone();
    }
  }

  /** * {@inheritdoc} */
  public static function getSubscribedEvents(): array {
    $events[ConfigEvents::SAVE][] = ['onConfigSave', 0];
    // The priority for this must run directly after the authentication     // subscriber.     $events[KernelEvents::REQUEST][] = ['setDefaultTimeZone', 299];
    
Home | Imprint | This part of the site doesn't use cookies.