Commit b71bc2c1 authored by alexpott's avatar alexpott

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
......@@ -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);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment