23

Issue

Uninstalling a feature which creates a content type hides the "Delete" link on the admin/structure/types.

Issue on Drupal.org

0

5 Answers 5

15

Solution

Using a hook_uninstall() in FEATURE_NAME.install file and changing the status of the content type, so the system thinks it is an unlocked, custom content type.

I posted this also on d.org.

<?php
/**
 * Implements hook_uninstall().
 */
function FEATURE_NAME_uninstall() {

  // List custom content types added by this feature
  $custom_ctypes = array(
    'blog',
  );

  // Go through each and unlock the content type
  foreach ($custom_ctypes as $ctype) {
    db_query("UPDATE {node_type} SET `custom` = 1, locked = 0 WHERE type = :ctype", array(':ctype' => $ctype));
  }

  // Clean Drupal cache; this is necessary for the "Delete" link to appear
  // next to the content type created by the feature.
  drupal_flush_all_caches();

}

This will make the "Delete" button appear for that content type, so you can delete it from the admin.

Hope this helps someone!

8
  • 1
    To clarify, this does not delete the content type; it makes the 'delete' link available in the content type listing page. Thanks @Ivanhoe123!
    – doub1ejack
    Commented Feb 1, 2013 at 18:50
  • 1
    Also, I was not able to do this while my features module was enabled, but after disabling & uninstalling (I used drush) this worked beautifully. Shortcut: use the devel module by dropping the contents of this function into /devel/php. To programmatically delete content type add node_type_delete($ctype); after the query in the for loop.
    – doub1ejack
    Commented Feb 1, 2013 at 19:05
  • Thanks for that code. After seeing this code i edited my database using phpMyAdmin and edited the "node_type" table. Then i found the contect type i waned to delete and set the "Custom" value to "1". And finnaly i deleted it from the Drupal Administration.
    – ANDiTKO
    Commented Mar 9, 2013 at 14:57
  • 2
    mysql> UPDATE node_type SET custom = 1, locked = 0 WHERE type = '<content type machine name>'; Commented Feb 18, 2014 at 20:00
  • @MarcoLazzeri's solution worked perfectly for me and was a lot better than having to update my feature module just to uninstall it.
    – donut
    Commented Jul 30, 2014 at 16:45
12

For me, the solution was to load the delete page manually since there is no "delete" link on the content types page. To do this, you just need to construct the URL yourself by following the same URL structure as the delete page for other content types:

admin/structure/types/manage/YOUR_CONTENT_TYPE_MACHINE_NAME/delete

This brought up the content type delete confirmation page, which then allowed me to delete the content type.

For reference, see this thread on Drupal.org:

https://drupal.org/node/1055460#comment-7297680

Regards,

@cmsdave

2
  • I just changed the display content type link at the end to delete and could remove the content type without a problem. This solution works!
    – cateye
    Commented Mar 22, 2014 at 9:22
  • Note: Before this would work I had to edit the feature's .info file and remove the content type, then it would actually delete.
    – Duncanmoo
    Commented Oct 21, 2014 at 10:47
3

The above method does not delete taxonomies, but this can be achieved by appending the following after disabling and uninstalling the module:

// Delete taxonomies.
$machine_names = array('taxonomy_a', 'taxonomy_b');
foreach ($machine_names as $machine_name) {
  $taxonomy = taxonomy_vocabulary_machine_name_load($machine_name);
  taxonomy_vocabulary_delete($taxonomy->vid);
}
1

Another solution that worked for me directly to the database in my development site. Remember to always backup your database.

To manually delete a content type that was created by a feature #16 what Nedjo suggests is the following:

  • Disable the feature. I've sometimes run into problems with this--a feature won't disable. In this case, remove the feature module code.
  • Determine the machine name of the content type to be deleted, e.g., 'mytype'.
  • In the database, revert the node_type table values to the defaults as if the content type were created manually through the UI:

mysql> UPDATE node_type SET module = 'node', custom = 1, modified = 1, locked = 0 WHERE type = 'mytype';

  • Clear caches to ensure the content type change is available.
  • Through the UI at admin/structure/types, delete the content type.
0

If you use admin_menu module, you will still see the delete links in pull-down menu Structure / Content types / [content type name] / Delete, even if they are not displayed on the content types page.

I would say it's pretty safe to use this delete link if you assure there are no other references to this content type anymore.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.