diff --git a/core/modules/datetime/datetime.module b/core/modules/datetime/datetime.module index b545c36..4901ffd 100644 --- a/core/modules/datetime/datetime.module +++ b/core/modules/datetime/datetime.module @@ -1120,3 +1120,23 @@ function datetime_range_years($string, $date = NULL) { } return array($min_year, $max_year); } + +/** + * Implements hook_form_BASE_FORM_ID_alter() for node forms. + */ +function datetime_form_node_form_alter(&$form, &$form_state, $form_id) { + // Alter the 'Authored on' date to use datetime. + $form['author']['date']['#type'] = 'datetime'; + $config = Drupal::config('system.date'); + $format = $config->get('formats.html_date') . ' ' . $config->get('formats.html_time'); + $form['author']['date']['#description'] = t('Format: %format. Leave blank to use the time of form submission.', array('%format' => datetime_format_example($format))); + unset($form['author']['date']['#maxlength']); +} + +/** + * Implements hook_node_prepare(). + */ +function datetime_node_prepare($node) { + // Prepare the 'Authored on' date to use datetime. + $node->date = new DrupalDateTime($node->created); +} diff --git a/core/modules/node/lib/Drupal/node/NodeFormController.php b/core/modules/node/lib/Drupal/node/NodeFormController.php index 4bc59fe..63f2553 100644 --- a/core/modules/node/lib/Drupal/node/NodeFormController.php +++ b/core/modules/node/lib/Drupal/node/NodeFormController.php @@ -42,7 +42,7 @@ protected function prepareEntity() { $node->created = REQUEST_TIME; } else { - $node->date = new DrupalDateTime($node->created); + $node->date = format_date($node->created, 'custom', 'Y-m-d H:i:s O'); // Remove the log message from the original node entity. $node->log = NULL; } @@ -187,11 +187,11 @@ public function form(array $form, array &$form_state) { '#weight' => -1, '#description' => t('Leave blank for %anonymous.', array('%anonymous' => $user_config->get('anonymous'))), ); - $format = variable_get('date_format_html_date', 'Y-m-d') . ' ' . variable_get('date_format_html_time', 'H:i:s'); $form['author']['date'] = array( - '#type' => 'datetime', + '#type' => 'textfield', '#title' => t('Authored on'), - '#description' => t('Format: %format. Leave blank to use the time of form submission.', array('%format' => datetime_format_example($format))), + '#maxlength' => 25, + '#description' => t('Format: %time. The date format is YYYY-MM-DD and %timezone is the time zone offset from UTC. Leave blank to use the time of form submission.', array('%time' => !empty($node->date) ? date_format(date_create($node->date), 'Y-m-d H:i:s O') : format_date($node->created, 'custom', 'Y-m-d H:i:s O'), '%timezone' => !empty($node->date) ? date_format(date_create($node->date), 'O') : format_date($node->created, 'custom', 'O'))), '#default_value' => !empty($node->date) ? $node->date : '', ); @@ -333,7 +333,8 @@ public function validate(array $form, array &$form_state) { // Validate the "authored on" field. // The date element contains the date object. - if ($node->date instanceOf DrupalDateTime && $node->date->hasErrors()) { + $date = $node->date instanceof DrupalDateTime ? $node->date : new DrupalDateTime($node->date); + if ($date->hasErrors()) { form_set_error('date', t('You have to specify a valid date.')); } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php index 3632867..ac024bb 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php @@ -25,7 +25,7 @@ class NodeTranslationUITest extends EntityTranslationUITest { * * @var array */ - public static $modules = array('language', 'translation_entity', 'node', 'field_ui'); + public static $modules = array('language', 'translation_entity', 'node', 'datetime', 'field_ui'); public static function getInfo() { return array( diff --git a/core/modules/node/node.info.yml b/core/modules/node/node.info.yml index 68681a8..777ec9e 100644 --- a/core/modules/node/node.info.yml +++ b/core/modules/node/node.info.yml @@ -5,5 +5,3 @@ package: Core version: VERSION core: 8.x configure: admin/structure/types -dependencies: - - datetime diff --git a/core/modules/node/node.install b/core/modules/node/node.install index 2e761ae..d4ec353 100644 --- a/core/modules/node/node.install +++ b/core/modules/node/node.install @@ -808,11 +808,9 @@ function node_update_8013() { } /** - * Enable Datetime module, which is now a required dependency. + * Empty update. See http://drupal.org/node/1836392. */ function node_update_8014() { - // Enable the datetime module. - module_enable(array('datetime')); } /** diff --git a/core/modules/system/lib/Drupal/system/Tests/Module/DependencyTest.php b/core/modules/system/lib/Drupal/system/Tests/Module/DependencyTest.php index 023f485..96955cd 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Module/DependencyTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Module/DependencyTest.php @@ -134,12 +134,12 @@ function testModuleEnableOrder() { $this->assertModules(array('module_test'), TRUE); \Drupal::state()->set('module_test.dependency', 'dependency'); // module_test creates a dependency chain: - // - forum depends on taxonomy, comment, history, and ban (via module_test) + // - forum depends on taxonomy, comment, datetime, history, and ban (via module_test) // - taxonomy depends on options // - options depends on number // - ban depends on php (via module_test) // The correct enable order is: - $expected_order = array('php', 'ban', 'comment', 'history', 'number', 'options', 'taxonomy', 'forum'); + $expected_order = array('php', 'ban', 'datetime', 'comment', 'history', 'number', 'options', 'taxonomy', 'forum'); // Enable the modules through the UI, verifying that the dependency chain // is correct. @@ -147,16 +147,17 @@ function testModuleEnableOrder() { $edit['modules[Core][forum][enable]'] = 'forum'; $this->drupalPost('admin/modules', $edit, t('Save configuration')); $this->assertModules(array('forum'), FALSE); - $this->assertText(t('You must enable the History, Taxonomy, Options, Number, Comment, Ban, PHP Filter modules to install Forum.')); + $this->assertText(t('You must enable the History, Taxonomy, Options, Number, Comment, Datetime, Ban, PHP Filter modules to install Forum.')); $edit['modules[Core][history][enable]'] = 'history'; $edit['modules[Core][options][enable]'] = 'options'; $edit['modules[Core][number][enable]'] = 'number'; $edit['modules[Core][taxonomy][enable]'] = 'taxonomy'; $edit['modules[Core][comment][enable]'] = 'comment'; + $edit['modules[Core][datetime][enable]'] = 'datetime'; $edit['modules[Core][ban][enable]'] = 'ban'; $edit['modules[Core][php][enable]'] = 'php'; $this->drupalPost('admin/modules', $edit, t('Save configuration')); - $this->assertModules(array('forum', 'ban', 'php', 'comment', 'history', 'taxonomy', 'options', 'number'), TRUE); + $this->assertModules(array('forum', 'ban', 'php', 'datetime', 'comment', 'history', 'taxonomy', 'options', 'number'), TRUE); // Check the actual order which is saved by module_test_modules_enabled(). $module_order = \Drupal::state()->get('system_test.module_enable_order') ?: array();