diff --git a/core/modules/node/lib/Drupal/node/NodeFormController.php b/core/modules/node/lib/Drupal/node/NodeFormController.php index 38f803d..5cce940 100644 --- a/core/modules/node/lib/Drupal/node/NodeFormController.php +++ b/core/modules/node/lib/Drupal/node/NodeFormController.php @@ -41,7 +41,6 @@ protected function prepareEntity(EntityInterface $node) { $node->created = REQUEST_TIME; } else { - $node->published_date = format_date($node->published, 'custom', 'Y-m-d H:i:s O'); // Remove the log message from the original node entity. $node->log = NULL; } @@ -230,8 +229,8 @@ public function form(array $form, array &$form_state, EntityInterface $node) { '#type' => 'textfield', '#title' => t('First published on'), '#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->published_date) ? date_format(date_create($node->published_date), 'Y-m-d H:i:s O') : format_date($node->published, 'custom', 'Y-m-d H:i:s O'), '%timezone' => !empty($node->published_date) ? date_format(date_create($node->published_date), 'O') : format_date($node->published, 'custom', 'O'))), - '#default_value' => !empty($node->published_date) ? $node->published_date : '', + '#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 when published.', array('%time' => !empty($node->published_date) ? date_format(date_create($node->published_date), 'Y-m-d H:i:s O') : format_date($node->published, 'custom', 'Y-m-d H:i:s O'), '%timezone' => !empty($node->published_date) ? date_format(date_create($node->published_date), 'O') : format_date($node->published, 'custom', 'O'))), + '#default_value' => empty($node->published) ? '' : format_date($node->published, 'custom', 'Y-m-d H:i:s O'), ); // Node options for administrators. @@ -371,9 +370,11 @@ public function validate(array $form, array &$form_state) { } // Validate the "first published on" field. - $published_date = new DrupalDateTime($node->published_date); - if ($published_date->hasErrors()) { - form_set_error('published_date', t('You have to specify a valid publication date.')); + if (!empty($node->published_date)) { + $published_date = new DrupalDateTime($node->published_date); + if ($published_date->hasErrors()) { + form_set_error('published_date', t('You have to specify a valid publication date.')); + } } // Invoke hook_validate() for node type specific validation and diff --git a/core/modules/node/node.install b/core/modules/node/node.install index ac88175..4e3f727 100644 --- a/core/modules/node/node.install +++ b/core/modules/node/node.install @@ -82,8 +82,8 @@ function node_schema() { 'published' => array( 'description' => 'The Unix timestamp when the node was first published.', 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, + 'not null' => FALSE, + 'default' => NULL, ), 'comment' => array( 'description' => 'Whether comments are allowed on this node: 0 = no, 1 = closed (read only), 2 = open (read/write).', @@ -723,8 +723,8 @@ function node_update_8014(&$sandbox) { $spec = array( 'description' => 'The Unix timestamp when the node was first published.', 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, + 'not null' => FALSE, + 'default' => NULL, ); $keys = array( 'indexes' => array( diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 47ad2c2..17aa0e7 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -1009,7 +1009,7 @@ function node_submit(Node $node) { $node->published = $node_published->getTimestamp(); } else { - $node->published = 0; + $node->published = NULL; } $node->validated = TRUE; @@ -1146,7 +1146,7 @@ function template_preprocess_node(&$variables) { $variables['node'] = $variables['elements']['#node']; $node = $variables['node']; - $variables['date'] = format_date($node->published); + $variables['date'] = (!empty($node->published)) ? format_date($node->published) : format_date($node->created); $variables['name'] = theme('username', array( 'account' => $node, 'link_attributes' => array('rel' => 'author'), diff --git a/core/modules/node/node.views.inc b/core/modules/node/node.views.inc index 5a73355..fa190b7 100644 --- a/core/modules/node/node.views.inc +++ b/core/modules/node/node.views.inc @@ -406,7 +406,7 @@ function node_views_data() { 'help' => t('Date in the form of CCYYMMDD.'), 'argument' => array( 'field' => 'published', - 'id' => 'node_published_fulldate', + 'id' => 'created_fulldate', ), ); @@ -415,7 +415,7 @@ function node_views_data() { 'help' => t('Date in the form of YYYYMM.'), 'argument' => array( 'field' => 'published', - 'id' => 'node_published_year_month', + 'id' => 'created_year_month', ), ); @@ -424,7 +424,7 @@ function node_views_data() { 'help' => t('Date in the form of YYYY.'), 'argument' => array( 'field' => 'published', - 'id' => 'node_published_year', + 'id' => 'created_year', ), ); @@ -433,7 +433,7 @@ function node_views_data() { 'help' => t('Date in the form of MM (01 - 12).'), 'argument' => array( 'field' => 'published', - 'id' => 'node_published_month', + 'id' => 'created_month', ), ); @@ -442,7 +442,7 @@ function node_views_data() { 'help' => t('Date in the form of DD (01 - 31).'), 'argument' => array( 'field' => 'published', - 'id' => 'node_published_day', + 'id' => 'created_day', ), ); @@ -451,7 +451,7 @@ function node_views_data() { 'help' => t('Date in the form of WW (01 - 53).'), 'argument' => array( 'field' => 'published', - 'id' => 'node_published_week', + 'id' => 'created_week', ), ); diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/NodePublishUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/NodePublishUpgradePathTest.php index 2391c1f..ff06f10 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/NodePublishUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/NodePublishUpgradePathTest.php @@ -51,7 +51,7 @@ public function testNodePublishedTimestampUpgrade() { $this->assertEqual($timestamp, $node->published, 'Published content has published timestamp.'); } else { - $this->assertEqual(0, $node->published, 'Unpublished content does not have published timestamp.'); + $this->assertEqual(NULL, $node->published, 'Unpublished content does not have published timestamp.'); } } }