diff --git a/core/modules/datetime/datetime.module b/core/modules/datetime/datetime.module index b545c36..65739cc 100644 --- a/core/modules/datetime/datetime.module +++ b/core/modules/datetime/datetime.module @@ -1120,3 +1120,22 @@ 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'; + $format = variable_get('date_format_html_date', 'Y-m-d') . ' ' . variable_get('date_format_html_time', 'H:i:s'); + $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/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 a4cc155..ee91a09 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. - update_module_enable(array('datetime')); } /**