diff --git a/modules/field_ui/field_ui.module b/modules/field_ui/field_ui.module index 27ef3c2..bf96b0d 100644 --- a/modules/field_ui/field_ui.module +++ b/modules/field_ui/field_ui.module @@ -48,6 +48,18 @@ function field_ui_help($path, $arg) { } /** + * Implements hook_field_attach_rename_bundle(). + */ +function field_ui_field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new) { + // The Field UI relies on entity_get_info() to build menu items for entity + // field administration pages. Clear the entity info cache and ensure that + // the menu is rebuilt. + entity_info_cache_clear(); + menu_rebuild(); +} + + +/** * Implements hook_menu(). */ function field_ui_menu() { diff --git a/modules/field_ui/field_ui.test b/modules/field_ui/field_ui.test index 9ff6c17..57f65df 100644 --- a/modules/field_ui/field_ui.test +++ b/modules/field_ui/field_ui.test @@ -411,6 +411,21 @@ class FieldUIManageFieldsTestCase extends FieldUITestCase { $this->drupalGet($bundle_path); $this->assertFalse($this->xpath('//select[@id="edit-add-existing-field-field-name"]//option[@value=:field_name]', array(':field_name' => $field_name)), t("The 'add existing field' select respects field types 'no_ui' property.")); } + + /** + * Test renaming a bundle. + */ + function testRenameBundle() { + $type2 = strtolower($this->randomName(8)) . '_' .'test'; + $hyphen_type2 = str_replace('_', '-', $type2); + + $options = array( + 'type' => $type2, + ); + $this->drupalPost('admin/structure/types/manage/' . $this->hyphen_type, $options, t('Save content type')); + + $this->drupalGet('admin/structure/types/manage/' . $hyphen_type2 . '/fields'); + } } /** diff --git a/modules/node/node.module b/modules/node/node.module index 7ff8d0b..eca8ccf 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -514,6 +514,9 @@ function node_type_save($info) { ->condition('type', $existing_type) ->execute(); + // Clear the node type cache before hooks are invoked. + node_type_cache_reset(); + if (!empty($type->old_type) && $type->old_type != $type->type) { field_attach_rename_bundle('node', $type->old_type, $type->type); } @@ -526,15 +529,15 @@ function node_type_save($info) { ->fields($fields) ->execute(); + // Clear the node_type cache before hooks are invoked. + node_type_cache_reset(); + field_attach_create_bundle('node', $type->type); module_invoke_all('node_type_insert', $type); $status = SAVED_NEW; } - // Clear the node type cache. - node_type_cache_reset(); - return $status; }