diff --git a/core/lib/Drupal/Core/Entity/EntityBCDecorator.php b/core/lib/Drupal/Core/Entity/EntityBCDecorator.php index a8eb5ad..06eae49 100644 --- a/core/lib/Drupal/Core/Entity/EntityBCDecorator.php +++ b/core/lib/Drupal/Core/Entity/EntityBCDecorator.php @@ -148,6 +148,13 @@ public function &__get($name) { * Directly writes to the plain field values, as done by Drupal 7. */ public function __set($name, $value) { + + // The property revision was used to create a new revision - do so as well. + // @TODO Did this apply only to node or for other entity types too? + if ($name == 'revision') { + $this->setNewRevision($value); + } + $defined = isset($this->definitions[$name]); // When updating values for entity properties that have been converted to // an entity field, directly write to the plain value. This makes it diff --git a/core/lib/Drupal/Core/Entity/EntityNG.php b/core/lib/Drupal/Core/Entity/EntityNG.php index f1b4979..70ac362 100644 --- a/core/lib/Drupal/Core/Entity/EntityNG.php +++ b/core/lib/Drupal/Core/Entity/EntityNG.php @@ -49,8 +49,6 @@ class EntityNG extends Entity { */ protected $values = array( 'langcode' => array(LANGUAGE_DEFAULT => array(0 => array('value' => LANGUAGE_NOT_SPECIFIED))), - 'newRevision' => array(LANGUAGE_DEFAULT => array(0 => array('value' => FALSE))), - 'isDefaultRevision' => array(LANGUAGE_DEFAULT => array(0 => array('value' => TRUE))), ); /** @@ -83,6 +81,11 @@ public function __construct(array $values, $entity_type, $bundle = FALSE) { $this->entityType = $entity_type; $this->bundle = $bundle ? $bundle : $this->entityType; foreach ($values as $key => $value) { + // If the key matches an existing property set the value to the property + // to ensure non converted properties have the correct value. + if (property_exists($this, $key) && isset($value[LANGUAGE_DEFAULT])) { + $this->$key = $value[LANGUAGE_DEFAULT]; + } $this->values[$key] = $value; } $this->init(); @@ -103,9 +106,6 @@ public function getType() { protected function init() { // We unset all defined properties, so magic getters apply. unset($this->langcode); - unset($this->enforceIsNew); - unset($this->newRevision); - unset($this->isDefaultRevision); } /** @@ -529,24 +529,4 @@ public function label($langcode = NULL) { } return $label; } - - /** - * Overrides Entity::isNewRevision(). - */ - public function isNewRevision() { - $info = $this->entityInfo(); - return $this->newRevision->value || (!empty($info['entity_keys']['revision']) && !$this->getRevisionId()); - } - - /** - * Overrides Entity::isDefaultRevision(). - */ - public function isDefaultRevision($new_value = NULL) { - $return = $this->isDefaultRevision->value; - if (isset($new_value)) { - $this->isDefaultRevision = (bool) $new_value; - } - return $return; - } - } diff --git a/core/modules/node/lib/Drupal/node/NodeStorageController.php b/core/modules/node/lib/Drupal/node/NodeStorageController.php index 31f9f32..5a0a3ae 100644 --- a/core/modules/node/lib/Drupal/node/NodeStorageController.php +++ b/core/modules/node/lib/Drupal/node/NodeStorageController.php @@ -237,18 +237,6 @@ public function baseFieldDefinitions() { 'description' => t('The node language code.'), 'type' => 'language_field', ); - $properties['newRevision'] = array( - 'label' => t('New revision'), - 'description' => t('A boolean indicating whether this is a new revision.'), - 'type' => 'boolean_field', - 'queryable' => FALSE, - ); - $properties['isDefaultRevision'] = array( - 'label' => t('Default revision'), - 'description' => t('A boolean indicating whether this version is the default revision.'), - 'type' => 'boolean_field', - 'queryable' => FALSE, - ); $properties['title'] = array( 'label' => t('Title'), 'description' => t('The title of this node, always treated as non-markup plain text.'), diff --git a/core/modules/node/lib/Drupal/node/Plugin/Core/Entity/Node.php b/core/modules/node/lib/Drupal/node/Plugin/Core/Entity/Node.php index 35beff1..9b8a991 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/Core/Entity/Node.php +++ b/core/modules/node/lib/Drupal/node/Plugin/Core/Entity/Node.php @@ -60,16 +60,6 @@ class Node extends EntityNG implements ContentEntityInterface { public $vid; /** - * Indicates whether this is the default node revision. - * - * The default revision of a node is the one loaded when no specific revision - * has been specified. Only default revisions are saved to the node table. - * - * @var boolean - */ - public $isDefaultRevision; - - /** * The node UUID. * * @var string diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsAllTestCase.php b/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsAllTestCase.php index 4703d11..90a7305 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsAllTestCase.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsAllTestCase.php @@ -64,7 +64,7 @@ function setUp() { $node->setNewRevision(); $node->save(); - $node = node_load($node->nid); // Make sure we get revision information. + $node = node_load($node->nid, TRUE); // Make sure we get revision information. $nodes[] = clone $node; } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php index d5ea7b5..46244b8 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php @@ -48,20 +48,24 @@ function setUp() { $logs = array(); // Get original node. - $nodes[] = $node; + $nodes[] = clone $node; // Create three revisions. $revision_count = 3; for ($i = 0; $i < $revision_count; $i++) { - $logs[] = $settings['log'] = $this->randomName(32); + $logs[] = $node->log = $this->randomName(32); - // Create revision with random title and body and update variables. - $this->drupalCreateNode($settings); - $node = node_load($node->nid); // Make sure we get revision information. - $settings = get_object_vars($node); - $settings['isDefaultRevision'] = TRUE; + // Create revision with a random title and body and update variables. + $node->title = $this->randomName(); + $node->body[$node->language()->langcode][0] = array( + 'value' => $this->randomName(32), + 'format' => filter_default_format(), + ); + $node->setNewRevision(); + $node->save(); - $nodes[] = $node; + $node = node_load($node->nid); // Make sure we get revision information. + $nodes[] = clone $node; } $this->nodes = $nodes; @@ -96,7 +100,7 @@ function testRevisions() { $this->assertRaw(t('@type %title has been reverted back to the revision from %revision-date.', array('@type' => 'Basic page', '%title' => $nodes[1]->label(), '%revision-date' => format_date($nodes[1]->revision_timestamp))), 'Revision reverted.'); - $reverted_node = node_load($node->nid); + $reverted_node = node_load($node->nid, TRUE); $this->assertTrue(($nodes[1]->body[LANGUAGE_NOT_SPECIFIED][0]['value'] == $reverted_node->body[LANGUAGE_NOT_SPECIFIED][0]['value']), 'Node reverted correctly.'); // Confirm that this is not the default version. diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeSaveTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeSaveTest.php index f8fdc93..e2f5f29 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeSaveTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeSaveTest.php @@ -55,9 +55,9 @@ function testImport() { 'uid' => $this->web_user->uid, 'type' => 'article', 'nid' => $test_nid, - 'enforceIsNew' => TRUE, ); $node = node_submit(entity_create('node', $node)); + $node->enforceIsNew(); // Verify that node_submit did not overwrite the user ID. $this->assertEqual($node->uid, $this->web_user->uid, 'Function node_submit() preserves user ID');