diff --git a/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php b/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php index 3ad3acf..c40ca66 100644 --- a/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php +++ b/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php @@ -1100,6 +1100,21 @@ public function onInstanceDelete(FieldInstanceInterface $instance) { * {@inheritdoc} */ public function onBundleRename($bundle, $bundle_new) { + if ($this->bundleKey) { + // Update entities to use new bundle name. + $this->database->update($this->entityInfo->getBaseTable()) + ->fields(array($this->bundleKey => $bundle_new)) + ->condition($this->bundleKey, $bundle) + ->execute(); + if ($data_table = $this->entityInfo->getDataTable()) { + // Update data_table if any. + $this->database->update($data_table) + ->fields(array($this->bundleKey => $bundle_new)) + ->condition($this->bundleKey, $bundle) + ->execute(); + } + } + // We need to account for deleted fields and instances. The method runs // before the instance definitions are updated, so we need to fetch them // using the old bundle name. diff --git a/core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php b/core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php index 28dc5eb..e0c866b 100644 --- a/core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php +++ b/core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php @@ -265,7 +265,7 @@ public function testBaseFieldComponent() { public function testRenameDeleteBundle() { $this->enableModules(array('field_test', 'node', 'system', 'text')); $this->installSchema('system', array('variable')); - $this->installSchema('node', array('node')); + $this->installSchema('node', array('node', 'node_field_data')); // Create a node bundle, display and form display object. entity_create('node_type', array('type' => 'article'))->save(); diff --git a/core/modules/node/lib/Drupal/node/Entity/NodeType.php b/core/modules/node/lib/Drupal/node/Entity/NodeType.php index cec3461..248ea18 100644 --- a/core/modules/node/lib/Drupal/node/Entity/NodeType.php +++ b/core/modules/node/lib/Drupal/node/Entity/NodeType.php @@ -179,16 +179,6 @@ public function postSave(EntityStorageControllerInterface $storage_controller, $ // Clear the node type cache to reflect the rename. \Drupal::cache()->deleteTags(array('node_types' => TRUE)); - $update_count = node_type_update_nodes($this->getOriginalId(), $this->id()); - if ($update_count) { - drupal_set_message(format_plural($update_count, - 'Changed the content type of 1 post from %old-type to %type.', - 'Changed the content type of @count posts from %old-type to %type.', - array( - '%old-type' => $this->getOriginalId(), - '%type' => $this->id(), - ))); - } entity_invoke_bundle_hook('rename', 'node', $this->getOriginalId(), $this->id()); } else { diff --git a/core/modules/node/node.module b/core/modules/node/node.module index b457cb9..29375c3 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -485,24 +485,6 @@ function node_field_extra_fields() { } /** - * Updates all nodes of one type to be of another type. - * - * @param string $old_id - * The current node type of the nodes. - * @param string $new_id - * The new node type of the nodes. - * - * @return - * The number of nodes whose node type field was modified. - */ -function node_type_update_nodes($old_id, $new_id) { - return db_update('node') - ->fields(array('type' => $new_id)) - ->condition('type', $old_id) - ->execute(); -} - -/** * Loads node entities from the database. * * This function should be used whenever you need to load more than one node