diff --git a/core/modules/datetime/datetime.module b/core/modules/datetime/datetime.module index b545c36..d964242 100644 --- a/core/modules/datetime/datetime.module +++ b/core/modules/datetime/datetime.module @@ -31,16 +31,25 @@ function datetime_element_info() { $format_type = datetime_default_format_type(); + // Date formats cannot be loaded during update. + if (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update') { + $date_format = ''; + $time_format = ''; + } + else { + $date_format = entity_load('date_format', 'html_date')->getPattern($format_type); + $time_format = entity_load('date_format', 'html_time')->getPattern($format_type); + } $types['datetime'] = array( '#input' => TRUE, '#element_validate' => array('datetime_datetime_validate'), '#process' => array('datetime_datetime_form_process'), '#theme' => 'datetime_form', '#theme_wrappers' => array('datetime_wrapper'), - '#date_date_format' => config('system.date')->get('formats.html_date.pattern.' . $format_type), + '#date_date_format' => $date_format, '#date_date_element' => 'date', '#date_date_callbacks' => array(), - '#date_time_format' => config('system.date')->get('formats.html_time.pattern.' . $format_type), + '#date_time_format' => $time_format, '#date_time_element' => 'time', '#date_time_callbacks' => array(), '#date_year_range' => '1900:2050', @@ -699,11 +708,11 @@ function datetime_html5_format($part, $element) { case 'date': switch ($element['#date_date_element']) { case 'date': - return config('system.date')->get('formats.html_date.pattern.' . $format_type); + return entity_load('date_format', 'html_date')->getPattern($format_type); case 'datetime': case 'datetime-local': - return config('system.date')->get('formats.html_datetime.pattern.' . $format_type); + return entity_load('date_format', 'html_datetime')->getPattern($format_type); default: return $element['#date_date_format']; @@ -713,7 +722,7 @@ function datetime_html5_format($part, $element) { case 'time': switch ($element['#date_time_element']) { case 'time': - return config('system.date')->get('formats.html_time.pattern.' . $format_type); + return entity_load('date_format', 'html_time')->getPattern($format_type); default: return $element['#date_time_format']; diff --git a/core/modules/datetime/lib/Drupal/datetime/Plugin/field/widget/DatetimeDefaultWidget.php b/core/modules/datetime/lib/Drupal/datetime/Plugin/field/widget/DatetimeDefaultWidget.php index f0c45c0..f4542eb 100644 --- a/core/modules/datetime/lib/Drupal/datetime/Plugin/field/widget/DatetimeDefaultWidget.php +++ b/core/modules/datetime/lib/Drupal/datetime/Plugin/field/widget/DatetimeDefaultWidget.php @@ -73,7 +73,7 @@ public function formElement(array $items, $delta, array $element, $langcode, arr case 'date': $date_type = 'date'; $time_type = 'none'; - $date_format = config('system.date')->get('formats.html_date.pattern.' . $format_type); + $date_format = entity_load('date_format', 'html_date')->getPattern($format_type); $time_format = ''; $element_format = $date_format; $storage_format = DATETIME_DATE_STORAGE_FORMAT; @@ -82,8 +82,8 @@ public function formElement(array $items, $delta, array $element, $langcode, arr default: $date_type = 'date'; $time_type = 'time'; - $date_format = config('system.date')->get('formats.html_date.pattern.' . $format_type); - $time_format = config('system.date')->get('formats.html_time.pattern.' . $format_type); + $date_format = entity_load('date_format', 'html_date')->getPattern($format_type); + $time_format = entity_load('date_format', 'html_time')->getPattern($format_type); $element_format = $date_format . ' ' . $time_format; $storage_format = DATETIME_DATETIME_STORAGE_FORMAT; break; diff --git a/core/modules/datetime/lib/Drupal/datetime/Tests/DatetimeFieldTest.php b/core/modules/datetime/lib/Drupal/datetime/Tests/DatetimeFieldTest.php index dd7712e..c52f952 100644 --- a/core/modules/datetime/lib/Drupal/datetime/Tests/DatetimeFieldTest.php +++ b/core/modules/datetime/lib/Drupal/datetime/Tests/DatetimeFieldTest.php @@ -94,8 +94,8 @@ function testDateField() { $value = '2012-12-31 00:00:00'; $date = new DrupalDateTime($value); $format_type = $date->canUseIntl() ? DrupalDateTime::INTL : DrupalDateTime::PHP; - $date_format = config('system.date')->get('formats.html_date.pattern.' . $format_type); - $time_format = config('system.date')->get('formats.html_time.pattern.' . $format_type); + $date_format = entity_load('date_format', 'html_date')->getPattern($format_type); + $time_format = entity_load('date_format', 'html_time')->getPattern($format_type); $edit = array( "{$this->field['field_name']}[$langcode][0][value][date]" => $date->format($date_format), @@ -163,8 +163,8 @@ function testDatetimeField() { $value = '2012-12-31 00:00:00'; $date = new DrupalDateTime($value); $format_type = $date->canUseIntl() ? DrupalDateTime::INTL : DrupalDateTime::PHP; - $date_format = config('system.date')->get('formats.html_date.pattern.' . $format_type); - $time_format = config('system.date')->get('formats.html_time.pattern.' . $format_type); + $date_format = entity_load('date_format', 'html_date')->getPattern($format_type); + $time_format = entity_load('date_format', 'html_time')->getPattern($format_type); $edit = array( "{$this->field['field_name']}[$langcode][0][value][date]" => $date->format($date_format), diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php b/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php index ed3c151..42d9656 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php @@ -38,7 +38,11 @@ function setUp() { $this->installSchema('entity_test', 'entity_test'); $this->installSchema('field_test', array('test_entity', 'test_entity_revision', 'test_entity_bundle')); - // Set default storage backend and configure the theme system. + // Set default storage backend and configure the theme system. If the child + // test depends on the language module, enable the language table first. + if ($this->container->get('module_handler')->moduleExists('language')) { + $this->installSchema('language', 'language'); + } $this->installConfig(array('field', 'system')); } diff --git a/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php b/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php index 4aa9613..5ddfce5 100644 --- a/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php @@ -36,7 +36,6 @@ public static function getInfo() { function setUp() { parent::setUp(); - $this->installSchema('language', array('language')); $this->installSchema('node', array('node_type')); $this->field_name = drupal_strtolower($this->randomName() . '_field_name'); diff --git a/core/modules/language/lib/Drupal/language/Tests/Views/LanguageTestBase.php b/core/modules/language/lib/Drupal/language/Tests/Views/LanguageTestBase.php index 9057a5a..85dbbfb 100644 --- a/core/modules/language/lib/Drupal/language/Tests/Views/LanguageTestBase.php +++ b/core/modules/language/lib/Drupal/language/Tests/Views/LanguageTestBase.php @@ -24,9 +24,8 @@ protected function setUp() { parent::setUp(); - $this->installSchema('language', 'language'); - $this->installSchema('system', 'variable'); + $this->installSchema('system', 'variable'); // Create English and another language beside English. $language = new Language(array('langcode' => 'en')); diff --git a/core/modules/system/lib/Drupal/system/DateFormatStorageController.php b/core/modules/system/lib/Drupal/system/DateFormatStorageController.php index cb46b37..6d28298 100644 --- a/core/modules/system/lib/Drupal/system/DateFormatStorageController.php +++ b/core/modules/system/lib/Drupal/system/DateFormatStorageController.php @@ -43,13 +43,15 @@ protected function postDelete($entities) { parent::postDelete($entities); // Clean up the localized entry if required. - $languages = language_list(); - foreach ($entities as $entity) { - $format_id = $entity->id(); - foreach ($languages as $langcode => $data) { - $config = config('locale.config.' . $langcode . '.system.date'); - if ($config->get($format_id)) { - $config->clear($format_id)->save(); + if (module_exists('language')) { + $languages = language_list(); + foreach ($entities as $entity) { + $format_id = $entity->id(); + foreach ($languages as $langcode => $data) { + $config = config('locale.config.' . $langcode . '.system.date'); + if ($config->get($format_id)) { + $config->clear($format_id)->save(); + } } } } diff --git a/core/modules/system/lib/Drupal/system/Plugin/Core/Entity/DateFormat.php b/core/modules/system/lib/Drupal/system/Plugin/Core/Entity/DateFormat.php index d88cfb2..2f30fae 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/Core/Entity/DateFormat.php +++ b/core/modules/system/lib/Drupal/system/Plugin/Core/Entity/DateFormat.php @@ -67,6 +67,13 @@ class DateFormat extends ConfigEntityBase implements DateFormatInterface { protected $pattern; /** + * The locked status of this date format. + * + * @var bool + */ + protected $locked = FALSE; + + /** * @var array */ protected $locales = array(); @@ -90,6 +97,7 @@ public function uri() { public function getExportProperties() { $properties = parent::getExportProperties(); $names = array( + 'locked', 'pattern', 'locales', ); diff --git a/core/modules/system/lib/Drupal/system/Tests/System/DateTimeTest.php b/core/modules/system/lib/Drupal/system/Tests/System/DateTimeTest.php index cf3e94c..11bf41f 100644 --- a/core/modules/system/lib/Drupal/system/Tests/System/DateTimeTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/System/DateTimeTest.php @@ -113,8 +113,8 @@ function testDateFormatConfiguration() { $this->assertText(t('Removed date format ' . $name), 'Custom date format removed.'); // Make sure the date does not exist in config. - $date_format = config('system.date')->get('formats.' . $date_format_id); - $this->assertIdentical($date_format, NULL); + $date_format = entity_load('date_format', $date_format_id); + $this->assertFalse($date_format); } /** diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/DateUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/DateUpgradePathTest.php index e1720d1..ce48a3d 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/DateUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/DateUpgradePathTest.php @@ -65,12 +65,12 @@ public function testDateUpgrade() { 'locked' => '0', ); + $actual_formats = entity_load_multiple('date_format', array_keys($expected_formats)); foreach ($expected_formats as $type => $format) { - $format_info = config('system.date')->get('formats.' . $type); - - $this->assertEqual($format_info['name'], $format['name'], format_string('Config value for @type name is the same', array('@type' => $type))); - $this->assertEqual($format_info['locked'], $format['locked'], format_string('Config value for @type locked is the same', array('@type' => $type))); - $this->assertEqual($format_info['pattern']['php'], $format['pattern']['php'], format_string('Config value for @type PHP date pattern is the same', array('@type' => $type))); + $format_info = $actual_formats[$type]; + $this->assertEqual($format_info->label(), $format['name'], format_string('Config value for @type name is the same', array('@type' => $type))); + $this->assertEqual($format_info->get('locked'), $format['locked'], format_string('Config value for @type locked is the same', array('@type' => $type))); + $this->assertEqual($format_info->getPattern(), $format['pattern']['php'], format_string('Config value for @type PHP date pattern is the same', array('@type' => $type))); // Make sure that the variable was deleted. $this->assertNull(update_variable_get('date_format_' . $type), format_string('Date format variable for @type was deleted.', array('@type' => $type))); diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 3824136..0e3170d 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -1,6 +1,7 @@ fetchAllAssoc('type', PDO::FETCH_ASSOC); if (!empty($date_formats)) { foreach ($date_formats as $type => $format) { // Set name and locked properties. - $config->set("formats.{$type}.name", $format['title']); - $config->set("formats.{$type}.locked", $format['locked']); + $config = config("system.date_format.$type") + ->set('id', $type) + ->set('label', $format['title']) + ->set('locked', $format['locked']) + ->set('status', 1) + ->set('uuid', $uuid->generate()); // Get the default date format for this type. $variable_name = 'date_format_' . $type; $default_format = update_variable_get($variable_name, NULL); if ($default_format) { // In Drupal 7 we only used PHP date types. - $config->set("formats.{$type}.pattern.php", $default_format); + $config->set('pattern.php', $default_format); // Delete the migrated variables. update_variable_del($variable_name); } + // Save the date configuration object. + $config->save(); } - - // Save the date configuration object. - $config->save(); } } diff --git a/core/modules/views/lib/Drupal/views/Tests/ViewUnitTestBase.php b/core/modules/views/lib/Drupal/views/Tests/ViewUnitTestBase.php index 134b97a..731875c 100644 --- a/core/modules/views/lib/Drupal/views/Tests/ViewUnitTestBase.php +++ b/core/modules/views/lib/Drupal/views/Tests/ViewUnitTestBase.php @@ -63,7 +63,11 @@ protected function setUpFixtures() { $query->execute(); // Tests implementing ViewUnitTestBase depend on the theme system being - // properly configured. + // properly configured. If the child test depends on the language module, + // enable the language table first. + if ($this->container->get('module_handler')->moduleExists('language')) { + $this->installSchema('language', 'language'); + } $this->installConfig(array('system')); ViewTestData::importTestViews(get_class($this), array('views_test_config')); } diff --git a/core/modules/views/lib/Drupal/views/Tests/Wizard/WizardPluginBaseUnitTest.php b/core/modules/views/lib/Drupal/views/Tests/Wizard/WizardPluginBaseUnitTest.php index 529d4f1..8d1e36e 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Wizard/WizardPluginBaseUnitTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Wizard/WizardPluginBaseUnitTest.php @@ -43,7 +43,6 @@ public static function getInfo() { protected function setUp() { parent::setUp(); - $this->installSchema('language', 'language'); $this->installSchema('system', 'variable'); $this->enableModules(array('views_ui'));