diff -u b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBundleBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBundleBase.php --- b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBundleBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBundleBase.php @@ -20,31 +20,6 @@ abstract class ConfigEntityBundleBase extends ConfigEntityBase { /** - * Renames displays when a bundle is renamed. - */ - protected function renameDisplays() { - // Rename entity displays. - if ($this->getOriginalId() !== $this->id()) { - foreach ($this->loadDisplays('entity_view_display') as $display) { - $new_id = $this->getEntityType()->getBundleOf() . '.' . $this->id() . '.' . $display->getMode(); - $display->set('id', $new_id); - $display->setTargetBundle($this->id()); - $display->save(); - } - } - - // Rename entity form displays. - if ($this->getOriginalId() !== $this->id()) { - foreach ($this->loadDisplays('entity_form_display') as $form_display) { - $new_id = $this->getEntityType()->getBundleOf() . '.' . $this->id() . '.' . $form_display->getMode(); - $form_display->set('id', $new_id); - $form_display->setTargetBundle($this->id()); - $form_display->save(); - } - } - } - - /** * Deletes display if a bundle is deleted. */ protected function deleteDisplays() { @@ -80,12 +55,6 @@ } // Entity bundle field definitions may depend on bundle settings. $entity_manager->clearCachedFieldDefinitions(); - - if ($this->getOriginalId() != $this->id()) { - // If the entity was renamed, update the displays. - $this->renameDisplays(); - $entity_manager->onBundleRename($this->getOriginalId(), $this->id(), $bundle_of); - } } } @@ -102,10 +71,17 @@ } /** - * {@inheritdoc} + * Acts on an entity before the presave hook is invoked. + * + * Used before the entity is saved and before invoking the presave hook. * * Ensure that config entities which are bundles of other entities cannot have * their ID changed. + * + * @param \Drupal\Core\Entity\EntityStorageInterface $storage + * The entity storage object. + * + * @throws \Drupal\Core\Config\ConfigNameException */ public function preSave(EntityStorageInterface $storage) { $bundle_type = $this->getEntityType(); @@ -113,7 +89,7 @@ if (!empty($bundle_of)) { /* @var \Drupal\Core\Entity\DynamicallyFieldableEntityStorageInterface $entity_storage */ - $entity_storage = \Drupal::entityManager()->getStorage($bundle_of); + $entity_storage = $this->entityManager()->getStorage($bundle_of); assert('$entity_storage instanceof DynamicallyFieldableEntityStorageInterface'); if ($entity_storage->hasData()) { only in patch2: unchanged: --- a/core/lib/Drupal/Core/Entity/EntityBundleListenerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityBundleListenerInterface.php @@ -8,7 +8,7 @@ namespace Drupal\Core\Entity; /** - * An interface for reacting to entity bundle creation, deletion, and renames. + * An interface for reacting to entity bundle creation and deletion. * * @todo Convert to Symfony events: https://www.drupal.org/node/2332935 */ @@ -25,20 +25,6 @@ public function onBundleCreate($bundle, $entity_type_id); /** - * Reacts to a bundle being renamed. - * - * This method runs before fields are updated with the new bundle name. - * - * @param string $bundle - * The name of the bundle being renamed. - * @param string $bundle_new - * The new name of the bundle. - * @param string $entity_type_id - * The entity type to which the bundle is bound; e.g. 'node' or 'user'. - */ - public function onBundleRename($bundle, $bundle_new, $entity_type_id); - - /** * Reacts to a bundle being deleted. * * This method runs before fields are deleted. only in patch2: unchanged: --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -1370,31 +1370,6 @@ public function onBundleCreate($bundle, $entity_type_id) { /** * {@inheritdoc} */ - public function onBundleRename($bundle_old, $bundle_new, $entity_type_id) { - $this->clearCachedBundles(); - // Notify the entity storage. - $storage = $this->getStorage($entity_type_id); - if ($storage instanceof EntityBundleListenerInterface) { - $storage->onBundleRename($bundle_old, $bundle_new, $entity_type_id); - } - - // Rename existing base field bundle overrides. - $overrides = $this->getStorage('base_field_override')->loadByProperties(array('entity_type' => $entity_type_id, 'bundle' => $bundle_old)); - foreach ($overrides as $override) { - $override->set('id', $entity_type_id . '.' . $bundle_new . '.' . $override->getName()); - $override->set('bundle', $bundle_new); - $override->allowBundleRename(); - $override->save(); - } - - // Invoke hook_entity_bundle_rename() hook. - $this->moduleHandler->invokeAll('entity_bundle_rename', array($entity_type_id, $bundle_old, $bundle_new)); - $this->clearCachedFieldDefinitions(); - } - - /** - * {@inheritdoc} - */ public function onBundleDelete($bundle, $entity_type_id) { $this->clearCachedBundles(); // Notify the entity storage. only in patch2: unchanged: --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php @@ -1496,40 +1496,6 @@ public function onBundleDelete($bundle, $entity_type_id) { } /** * {@inheritdoc} */ - public function onBundleRename($bundle, $bundle_new, $entity_type_id) { - // The method runs before the field definitions are updated, so we use the - // old bundle name. - $field_definitions = $this->entityManager->getFieldDefinitions($this->entityTypeId, $bundle); - // We need to handle deleted fields too. For now, this only makes sense for - // configurable fields, so we use the specific API. - // @todo Use the unified store of deleted field definitions instead in - // https://www.drupal.org/node/2282119 - $field_definitions += entity_load_multiple_by_properties('field_config', array('entity_type' => $this->entityTypeId, 'bundle' => $bundle, 'deleted' => TRUE, 'include_deleted' => TRUE)); - $table_mapping = $this->getTableMapping(); - - foreach ($field_definitions as $field_definition) { - $storage_definition = $field_definition->getFieldStorageDefinition(); - if ($table_mapping->requiresDedicatedTableStorage($storage_definition)) { - $is_deleted = $this->storageDefinitionIsDeleted($storage_definition); - $table_name = $table_mapping->getDedicatedDataTableName($storage_definition, $is_deleted); - $revision_name = $table_mapping->getDedicatedRevisionTableName($storage_definition, $is_deleted); - $this->database->update($table_name) - ->fields(array('bundle' => $bundle_new)) - ->condition('bundle', $bundle) - ->execute(); - if ($this->entityType->isRevisionable()) { - $this->database->update($revision_name) - ->fields(array('bundle' => $bundle_new)) - ->condition('bundle', $bundle) - ->execute(); - } - } - } - } - - /** - * {@inheritdoc} - */ protected function readFieldItemsToPurge(FieldDefinitionInterface $field_definition, $batch_size) { // Check whether the whole field storage definition is gone, or just some // bundle fields. only in patch2: unchanged: --- a/core/lib/Drupal/Core/Entity/entity.api.php +++ b/core/lib/Drupal/Core/Entity/entity.api.php @@ -139,8 +139,8 @@ * - Field configuration preSave(): hook_field_storage_config_update_forbid() * - Node postSave(): hook_node_access_records() and * hook_node_access_records_alter() - * - Config entities that are acting as entity bundles, in postSave(): - * hook_entity_bundle_create() or hook_entity_bundle_rename() as appropriate + * - Config entities that are acting as entity bundles in postSave(): + * hook_entity_bundle_create() * - Comment: hook_comment_publish() and hook_comment_unpublish() as * appropriate. * @@ -741,31 +741,6 @@ function hook_entity_bundle_create($entity_type_id, $bundle) { } /** - * Act on entity_bundle_rename(). - * - * This hook is invoked after the operation has been performed. - * - * @param string $entity_type_id - * The entity type to which the bundle is bound. - * @param string $bundle_old - * The previous name of the bundle. - * @param string $bundle_new - * The new name of the bundle. - * - * @see entity_crud - */ -function hook_entity_bundle_rename($entity_type_id, $bundle_old, $bundle_new) { - // Update the settings associated with the bundle in my_module.settings. - $config = \Drupal::config('my_module.settings'); - $bundle_settings = $config->get('bundle_settings'); - if (isset($bundle_settings[$entity_type_id][$bundle_old])) { - $bundle_settings[$entity_type_id][$bundle_new] = $bundle_settings[$entity_type_id][$bundle_old]; - unset($bundle_settings[$entity_type_id][$bundle_old]); - $config->set('bundle_settings', $bundle_settings); - } -} - -/** * Act on entity_bundle_delete(). * * This hook is invoked after the operation has been performed. only in patch2: unchanged: --- a/core/lib/Drupal/Core/Field/Entity/BaseFieldOverride.php +++ b/core/lib/Drupal/Core/Field/Entity/BaseFieldOverride.php @@ -163,8 +163,7 @@ protected function getBaseFieldDefinition() { * {@inheritdoc} * * @throws \Drupal\Core\Field\FieldException - * If the bundle is being changed and - * BaseFieldOverride::allowBundleRename() has not been called. + * If the bundle is being changed. */ public function preSave(EntityStorageInterface $storage) { // Filter out unknown settings and make sure all settings are present, so @@ -189,7 +188,7 @@ public function preSave(EntityStorageInterface $storage) { if ($this->entity_type != $this->original->entity_type) { throw new FieldException("Cannot change the entity_type of an existing base field bundle override (entity type:{$this->entity_type}, bundle:{$this->original->bundle}, field name: {$this->field_name})"); } - if ($this->bundle != $this->original->bundle && empty($this->bundleRenameAllowed)) { + if ($this->bundle != $this->original->bundle) { throw new FieldException("Cannot change the bundle of an existing base field bundle override (entity type:{$this->entity_type}, bundle:{$this->original->bundle}, field name: {$this->field_name})"); } $previous_definition = $this->original; only in patch2: unchanged: --- a/core/lib/Drupal/Core/Field/FieldConfigBase.php +++ b/core/lib/Drupal/Core/Field/FieldConfigBase.php @@ -180,13 +180,6 @@ protected $itemDefinition; /** - * Flag indicating whether the bundle name can be renamed or not. - * - * @var bool - */ - protected $bundleRenameAllowed = FALSE; - - /** * Array of constraint options keyed by constraint plugin ID. * * @var array @@ -456,7 +449,7 @@ public function __sleep() { // Only serialize necessary properties, excluding those that can be // recalculated. $properties = get_object_vars($this); - unset($properties['fieldStorage'], $properties['itemDefinition'], $properties['bundleRenameAllowed'], $properties['original']); + unset($properties['fieldStorage'], $properties['itemDefinition'], $properties['original']); return array_keys($properties); } @@ -531,13 +524,6 @@ public function getItemDefinition() { /** * {@inheritdoc} */ - public function allowBundleRename() { - $this->bundleRenameAllowed = TRUE; - } - - /** - * {@inheritdoc} - */ public function getConfig($bundle) { return $this; } only in patch2: unchanged: --- a/core/lib/Drupal/Core/Field/FieldConfigInterface.php +++ b/core/lib/Drupal/Core/Field/FieldConfigInterface.php @@ -282,13 +282,4 @@ public function addConstraint($constraint_name, $options = NULL); */ public function setConstraints(array $constraints); - /** - * Allows a bundle to be renamed. - * - * Renaming a bundle on the instance is allowed when an entity's bundle - * is renamed and when field_entity_bundle_rename() does internal - * housekeeping. - */ - public function allowBundleRename(); - } only in patch2: unchanged: --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -187,30 +187,6 @@ function field_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundl } /** - * Implements hook_entity_bundle_rename(). - */ -function field_entity_bundle_rename($entity_type, $bundle_old, $bundle_new) { - $fields = entity_load_multiple_by_properties('field_config', array('entity_type' => $entity_type, 'bundle' => $bundle_old, 'include_deleted' => TRUE)); - foreach ($fields as $field) { - $id_new = $field->getTargetEntityTypeId() . '.' . $bundle_new . '.' . $field->getName(); - $field->set('id', $id_new); - $field->set('bundle', $bundle_new); - // Save non-deleted fields. - if (!$field->isDeleted()) { - $field->allowBundleRename(); - $field->save(); - } - // Update deleted fields directly in the state storage. - else { - $state = \Drupal::state(); - $deleted_fields = $state->get('field.field.deleted') ?: array(); - $deleted_fields[$field->uuid] = $field->toArray(); - $state->set('field.field.deleted', $deleted_fields); - } - } -} - -/** * Implements hook_entity_bundle_delete(). * * This deletes the data for the field as well as the field themselves. This only in patch2: unchanged: --- a/core/modules/field/src/Entity/FieldConfig.php +++ b/core/modules/field/src/Entity/FieldConfig.php @@ -167,7 +167,7 @@ public function preSave(EntityStorageInterface $storage) { if ($this->entity_type != $this->original->entity_type) { throw new FieldException("Cannot change an existing field's entity_type."); } - if ($this->bundle != $this->original->bundle && empty($this->bundleRenameAllowed)) { + if ($this->bundle != $this->original->bundle) { throw new FieldException("Cannot change an existing field's bundle."); } if ($storage_definition->uuid() != $this->original->getFieldStorageDefinition()->uuid()) { only in patch2: unchanged: --- a/core/modules/field/src/Tests/FieldAttachStorageTest.php +++ b/core/modules/field/src/Tests/FieldAttachStorageTest.php @@ -275,9 +275,9 @@ function testFieldAttachDelete() { } /** - * Test entity_bundle_create() and entity_bundle_rename(). + * Test entity_bundle_create(). */ - function testEntityCreateRenameBundle() { + function testEntityCreateBundle() { $entity_type = 'entity_test_rev'; $this->createFieldWithStorage('', $entity_type); $cardinality = $this->fieldTestData->field_storage->getCardinality(); @@ -298,20 +298,6 @@ function testEntityCreateRenameBundle() { // Verify the field data is present on load. $entity = $this->entitySaveReload($entity); $this->assertEqual(count($entity->{$this->fieldTestData->field_name}), $cardinality, "Data is retrieved for the new bundle"); - - // Rename the bundle. - $new_bundle = 'test_bundle_' . Unicode::strtolower($this->randomMachineName()); - entity_test_rename_bundle($this->fieldTestData->field_definition['bundle'], $new_bundle, $entity_type); - - // Check that the field definition has been updated. - $this->fieldTestData->field = FieldConfig::loadByName($entity_type, $new_bundle, $this->fieldTestData->field_name); - $this->assertIdentical($this->fieldTestData->field->getTargetBundle(), $new_bundle, "Bundle name has been updated in the field."); - - // Verify the field data is present on load. - $controller = $this->container->get('entity.manager')->getStorage($entity->getEntityTypeId()); - $controller->resetCache(); - $entity = $controller->load($entity->id()); - $this->assertEqual(count($entity->{$this->fieldTestData->field_name}), $cardinality, "Bundle name has been updated in the field storage"); } /** only in patch2: unchanged: --- a/core/modules/field_ui/field_ui.module +++ b/core/modules/field_ui/field_ui.module @@ -108,15 +108,6 @@ function field_ui_entity_bundle_create($entity_type, $bundle) { } /** - * Implements hook_entity_bundle_rename(). - */ -function field_ui_entity_bundle_rename($entity_type, $bundle_old, $bundle_new) { - // When a bundle is renamed, the menu needs to be rebuilt to add our - // menu item tabs. - \Drupal::service('router.builder')->setRebuildNeeded(); -} - -/** * Implements hook_form_FORM_ID_alter(). * * Adds a button 'Save and manage fields' to the 'Create content type' form. only in patch2: unchanged: --- a/core/modules/field_ui/src/Tests/EntityDisplayTest.php +++ b/core/modules/field_ui/src/Tests/EntityDisplayTest.php @@ -300,9 +300,9 @@ public function testBaseFieldComponent() { } /** - * Tests renaming and deleting a bundle. + * Tests deleting a bundle. */ - public function testRenameDeleteBundle() { + public function testDeleteBundle() { // Create a node bundle, display and form display object. $type = NodeType::create(array('type' => 'article')); $type->save(); @@ -310,39 +310,6 @@ public function testRenameDeleteBundle() { entity_get_display('node', 'article', 'default')->save(); entity_get_form_display('node', 'article', 'default')->save(); - // Rename the article bundle and assert the entity display is renamed. - $type->old_type = 'article'; - $type->set('type', 'article_rename'); - $type->save(); - $old_display = entity_load('entity_view_display', 'node.article.default'); - $this->assertFalse((bool) $old_display); - $old_form_display = entity_load('entity_form_display', 'node.article.default'); - $this->assertFalse((bool) $old_form_display); - $new_display = entity_load('entity_view_display', 'node.article_rename.default'); - $this->assertEqual('article_rename', $new_display->getTargetBundle()); - $this->assertEqual('node.article_rename.default', $new_display->id()); - $new_form_display = entity_load('entity_form_display', 'node.article_rename.default'); - $this->assertEqual('article_rename', $new_form_display->getTargetBundle()); - $this->assertEqual('node.article_rename.default', $new_form_display->id()); - - $expected_view_dependencies = array( - 'config' => array('field.field.node.article_rename.body', 'node.type.article_rename'), - 'module' => array('entity_test', 'text', 'user') - ); - // Check that the display has dependencies on the bundle, fields and the - // modules that provide the formatters. - $dependencies = $new_display->calculateDependencies(); - $this->assertEqual($expected_view_dependencies, $dependencies); - - // Check that the form display has dependencies on the bundle, fields and - // the modules that provide the formatters. - $dependencies = $new_form_display->calculateDependencies(); - $expected_form_dependencies = array( - 'config' => array('field.field.node.article_rename.body', 'node.type.article_rename'), - 'module' => array('text') - ); - $this->assertEqual($expected_form_dependencies, $dependencies); - // Delete the bundle. $type->delete(); $display = entity_load('entity_view_display', 'node.article_rename.default'); only in patch2: unchanged: --- a/core/modules/field_ui/src/Tests/ManageFieldsTest.php +++ b/core/modules/field_ui/src/Tests/ManageFieldsTest.php @@ -590,19 +590,6 @@ function testHiddenFields() { } /** - * Tests renaming a bundle. - */ - function testRenameBundle() { - $type2 = strtolower($this->randomMachineName(8)) . '_test'; - - $options = array( - 'type' => $type2, - ); - $this->drupalPostForm('admin/structure/types/manage/' . $this->contentType, $options, t('Save content type')); - $this->manageFieldsPage($type2); - } - - /** * Tests that a duplicate field name is caught by validation. */ function testDuplicateFieldName() { only in patch2: unchanged: --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -218,15 +218,6 @@ function language_configuration_element_submit(&$form, FormStateInterface $form_ } /** - * Implements hook_entity_bundle_rename(). - */ -function language_entity_bundle_rename($entity_type_id, $bundle_old, $bundle_new) { - ContentLanguageSettings::loadByEntityTypeBundle($entity_type_id, $bundle_old) - ->setTargetBundle($bundle_new) - ->save(); -} - -/** * Implements hook_entity_bundle_delete(). */ function language_entity_bundle_delete($entity_type_id, $bundle) { only in patch2: unchanged: --- a/core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php +++ b/core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php @@ -470,35 +470,6 @@ function testFieldSqlStorageForeignKeys() { } /** - * Tests reacting to a bundle being renamed. - */ - function testFieldSqlStorageBundleRename() { - $entity_type = $bundle = 'entity_test_rev'; - $field_name = $this->fieldStorage->getName(); - - // Create an entity. - $value = mt_rand(1, 127); - $entity = entity_create($entity_type, array( - 'type' => $bundle, - $field_name => $value, - )); - $entity->save(); - - // Rename the bundle. - $bundle_new = $bundle . '_renamed'; - entity_test_rename_bundle($bundle, $bundle_new, $entity_type); - - // Check that the 'bundle' column has been updated in storage. - $row = db_select($this->table, 't') - ->fields('t', array('bundle', $field_name . '_value')) - ->condition('entity_id', $entity->id()) - ->execute() - ->fetch(); - $this->assertEqual($row->bundle, $bundle_new); - $this->assertEqual($row->{$field_name . '_value'}, $value); - } - - /** * Tests table name generation. */ public function testTableNames() { only in patch2: unchanged: --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -171,26 +171,6 @@ function entity_test_create_bundle($bundle, $text = NULL, $entity_type = 'entity } /** - * Renames a bundle for entity_test entities. - * - * @param string $bundle_old - * The machine-readable name of the bundle to rename. - * @param string $bundle_new - * The new machine-readable name of the bundle. - * @param string $entity_type - * (optional) The entity type for which the bundle is renamed. Defaults to - * 'entity_test'. - */ -function entity_test_rename_bundle($bundle_old, $bundle_new, $entity_type = 'entity_test') { - $bundles = \Drupal::state()->get($entity_type . '.bundles') ?: array($entity_type => array('label' => 'Entity Test Bundle')); - $bundles[$bundle_new] = $bundles[$bundle_old]; - unset($bundles[$bundle_old]); - \Drupal::state()->set($entity_type . '.bundles', $bundles); - - \Drupal::entityManager()->onBundleRename($bundle_old, $bundle_new, $entity_type); -} - -/** * Deletes a bundle for entity_test entities. * * @param string $bundle only in patch2: unchanged: --- a/core/modules/taxonomy/src/Entity/Vocabulary.php +++ b/core/modules/taxonomy/src/Entity/Vocabulary.php @@ -125,48 +125,6 @@ public function getDescription() { /** * {@inheritdoc} */ - public function postSave(EntityStorageInterface $storage, $update = TRUE) { - parent::postSave($storage, $update); - - if ($update && $this->getOriginalId() != $this->id() && !$this->isSyncing()) { - // Reflect machine name changes in the definitions of existing 'taxonomy' - // fields. - $field_ids = array(); - $field_map = \Drupal::entityManager()->getFieldMapByFieldType('entity_reference'); - foreach ($field_map as $entity_type => $field_storages) { - foreach ($field_storages as $field_storage => $info) { - $field_ids[] = $entity_type . '.' . $field_storage; - } - } - - $field_storages = \Drupal::entityManager()->getStorage('field_storage_config')->loadMultiple($field_ids); - $taxonomy_fields = array_filter($field_storages, function ($field_storage) { - return $field_storage->getType() == 'entity_reference' && $field_storage->getSetting('target_type') == 'taxonomy_term'; - }); - - foreach ($taxonomy_fields as $field_storage) { - $update_storage = FALSE; - - $allowed_values = $field_storage->getSetting('allowed_values'); - foreach ($allowed_values as &$value) { - if ($value['vocabulary'] == $this->getOriginalId()) { - $value['vocabulary'] = $this->id(); - $update_storage = TRUE; - } - } - $field_storage->setSetting('allowed_values', $allowed_values); - - if ($update_storage) { - $field_storage->save(); - } - } - } - $storage->resetCache($update ? array($this->getOriginalId()) : array()); - } - - /** - * {@inheritdoc} - */ public static function preDelete(EntityStorageInterface $storage, array $entities) { parent::preDelete($storage, $entities);