diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php
index 8651134..534a597 100644
--- a/core/lib/Drupal/Core/DrupalKernel.php
+++ b/core/lib/Drupal/Core/DrupalKernel.php
@@ -537,4 +537,12 @@ protected function getModuleNamespaces($moduleFileNames) {
protected function registerNamespaces(array $namespaces = array()) {
$this->classLoader->addPrefixes($namespaces);
}
+
+ public function serialize() {
+ return serialize(array($this->environment, $this->debug, $this->classLoader, $this->allowDumping));
+ }
+ public function unserialize($data) {
+ list($environment, $debug, $class_loader, $allow_dumping) = unserialize($data);
+ $this->__construct($environment, $debug, $class_loader, $allow_dumping);
+ }
}
diff --git a/core/modules/system/lib/Drupal/system/Form/DateFormatAddForm.php b/core/modules/system/lib/Drupal/system/Form/DateFormatAddForm.php
index 1201e6d..6dec855 100644
--- a/core/modules/system/lib/Drupal/system/Form/DateFormatAddForm.php
+++ b/core/modules/system/lib/Drupal/system/Form/DateFormatAddForm.php
@@ -7,8 +7,6 @@
namespace Drupal\system\Form;
-use Drupal\Core\Datetime\DrupalDateTime;
-
/**
* Provides an add form for date formats.
*/
@@ -34,8 +32,6 @@ public function buildForm(array $form, array &$form_state) {
'#default_value' => '',
);
- $now = '';
-
$form['date_format_id'] = array(
'#type' => 'machine_name',
'#title' => t('Machine-readable name'),
@@ -58,8 +54,8 @@ public function buildForm(array $form, array &$form_state) {
'#title' => t('Format string'),
'#maxlength' => 100,
'#description' => $description,
- '#default_value' => empty($pattern) ? '' : $pattern,
- '#field_suffix' => ' ' . $now . '',
+ '#default_value' => '',
+ '#field_suffix' => ' ',
'#ajax' => array(
'callback' => 'system_date_time_lookup',
'event' => 'keyup',
@@ -95,4 +91,3 @@ public function buildForm(array $form, array &$form_state) {
}
}
-
diff --git a/core/modules/system/lib/Drupal/system/Form/DateFormatEditForm.php b/core/modules/system/lib/Drupal/system/Form/DateFormatEditForm.php
index 62c7495..56afe28 100644
--- a/core/modules/system/lib/Drupal/system/Form/DateFormatEditForm.php
+++ b/core/modules/system/lib/Drupal/system/Form/DateFormatEditForm.php
@@ -7,12 +7,42 @@
namespace Drupal\system\Form;
-use Drupal\Core\Datetime\DrupalDateTime;
+use Drupal\Core\Config\ConfigFactory;
+use Drupal\Core\ControllerInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides an edit form for date formats.
*/
-class DateFormatEditForm extends DateFormatFormBase {
+class DateFormatEditForm extends DateFormatFormBase implements ControllerInterface {
+
+ /**
+ * The config object.
+ *
+ * @var \Drupal\Core\Config\Config
+ */
+ protected $config;
+
+ /**
+ * Constructs a new date format form.
+ *
+ * @param \Drupal\Core\Config\ConfigFactory $config_factory
+ * The config factory object.
+ */
+ public function __construct(ConfigFactory $config_factory) {
+ parent::__construct();
+
+ $this->config = $config_factory->get('system.date');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function create(ContainerInterface $container) {
+ return new static(
+ $container->get('config.factory')
+ );
+ }
/**
* {@inheritdoc}
@@ -26,10 +56,8 @@ public function getFormID() {
*/
public function buildForm(array $form, array &$form_state, $date_format_id = NULL) {
form_load_include($form_state, 'admin.inc', 'system');
- $format_info = config('system.date')->get('formats.' . $date_format_id);
- $patterns = $format_info['pattern'];
- $date = new DrupalDateTime();
- $pattern = $date->canUseIntl() ? $patterns[DrupalDateTime::INTL] : $patterns[DrupalDateTime::PHP];
+ $format_info = $this->config->get('formats.' . $date_format_id);
+ $pattern = $this->patternType ? $format_info['pattern'][$this->patternType] : '';
$form['date_format_name'] = array(
'#type' => 'textfield',
@@ -64,7 +92,7 @@ public function buildForm(array $form, array &$form_state, $date_format_id = NUL
'#title' => t('Format string'),
'#maxlength' => 100,
'#description' => $description,
- '#default_value' => empty($pattern) ? '' : $pattern,
+ '#default_value' => $pattern,
'#field_suffix' => ' ' . $now . '',
'#ajax' => array(
'callback' => 'system_date_time_lookup',
diff --git a/core/modules/system/lib/Drupal/system/Form/DateFormatFormBase.php b/core/modules/system/lib/Drupal/system/Form/DateFormatFormBase.php
index 536e03f..eef17d8 100644
--- a/core/modules/system/lib/Drupal/system/Form/DateFormatFormBase.php
+++ b/core/modules/system/lib/Drupal/system/Form/DateFormatFormBase.php
@@ -9,6 +9,7 @@
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Form\FormInterface;
+use Drupal\Component\Utility\String;
/**
* Provides a base form for date formats.
@@ -16,6 +17,21 @@
abstract class DateFormatFormBase implements FormInterface {
/**
+ * The date pattern type.
+ *
+ * @var string
+ */
+ protected $patternType;
+
+ /**
+ * Constructs a new date format form.
+ */
+ public function __construct() {
+ $date = new DrupalDateTime();
+ $this->patternType = $date->canUseIntl() ? DrupalDateTime::INTL : DrupalDateTime::PHP;
+ }
+
+ /**
* {@inheritdoc}
*/
public function validateForm(array &$form, array &$form_state) {
@@ -34,11 +50,9 @@ public function validateForm(array &$form, array &$form_state) {
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
- $date = new DrupalDateTime();
- $pattern_type = $date->canUseIntl() ? DrupalDateTime::INTL : DrupalDateTime::PHP;
$format = array();
- $format['name'] = check_plain($form_state['values']['date_format_name']);
- $format['pattern'][$pattern_type] = trim($form_state['values']['date_format_pattern']);
+ $format['name'] = String::checkPlain($form_state['values']['date_format_name']);
+ $format['pattern'][$this->patternType] = trim($form_state['values']['date_format_pattern']);
$format['locales'] = !empty($form_state['values']['date_langcode']) ? $form_state['values']['date_langcode'] : array();
// Formats created in the UI are not locked.
$format['locked'] = 0;