Skip to content
Snippets Groups Projects
Commit b71bc2c1 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #1950326 by swentel: Fixed Entity displays are not renamed/deleted when...

Issue #1950326 by swentel: Fixed Entity displays are not renamed/deleted when a bundle is renamed/deleted.
parent 291dbd54
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -7,3 +7,39 @@
* The module is mostly an anchor point for configuration items owned by the
* entity system.
*/
use Drupal\Core\Config\Entity\ConfigStorageController;
/**
* Implements hook_field_attach_rename_bundle().
*/
function entity_field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new) {
$entity_info = entity_get_info('entity_display');
// Rename entity displays.
if ($bundle_old !== $bundle_new) {
$ids = config_get_storage_names_with_prefix('entity.display.' . $entity_type . '.' . $bundle_old);
foreach ($ids as $id) {
$id = ConfigStorageController::getIDFromConfigName($id, $entity_info['config_prefix']);
$display = entity_load('entity_display', $id);
$new_id = $entity_type . '.' . $bundle_new . '.' . $display->viewMode;
$display->id = $new_id;
$display->bundle = $bundle_new;
$display->save();
}
}
}
/**
* Implements hook_field_attach_delete_bundle().
*/
function entity_field_attach_delete_bundle($entity_type, $bundle, $instances) {
$entity_info = entity_get_info('entity_display');
// Remove entity displays of the deleted bundle.
$ids = config_get_storage_names_with_prefix('entity.display.' . $entity_type . '.' . $bundle);
foreach ($ids as &$id) {
$id = ConfigStorageController::getIDFromConfigName($id, $entity_info['config_prefix']);
}
entity_delete_multiple('entity_display', $ids);
}
......@@ -198,4 +198,33 @@ public function testFieldComponent() {
$this->assertEqual($formatter->getPluginId(), $default_formatter);
}
/**
* Tests renaming and deleting a bundle.
*/
public function testRenameDeleteBundle() {
$this->enableModules(array('field_sql_storage', 'field_test', 'node', 'system'));
$this->installSchema('node', array('node_type'));
$this->installSchema('system', array('variable'));
// Create a node bundle and display object.
node_type_save((object) array('type' => 'article'));
entity_get_display('node', 'article', 'default')->save();
// Rename the article bundle and assert the entity display is renamed.
$info = node_type_load('article');
$info->old_type = 'article';
$info->type = 'article_rename';
node_type_save($info);
$old_display = entity_load('entity_display', 'node.article.default');
$this->assertFalse($old_display);
$new_display = entity_load('entity_display', 'node.article_rename.default');
$this->assertEqual('article_rename', $new_display->bundle);
$this->assertEqual('node.article_rename.default', $new_display->id);
// Delete the bundle.
node_type_delete('article_rename');
$display = entity_load('entity_display', 'node.article_rename.default');
$this->assertFalse($display);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment