I have created a custom content-type in my custom module with custom fields.. It works fine.. But when I try to uninstall it, it doesnt call hook_unistall().. Can any one suggest what can be the problem ?

Here is my code :

function homepage_blocks_uninstall() {
    $sql = 'SELECT nid FROM {node} n WHERE n.type = :type';
    $result = db_query($sql, array(':type' => 'homepage_blocks'));

    //echo "hello";

    $nids = array();
    foreach ($result as $row) {
        $nids[] = $row->nid;

    foreach (array_keys(_homepage_blocks_installed_fields()) as $field) {

    $instances = field_info_instances('node', 'homepage_blocks');
    foreach (_homepage_blocks_installed_instances() as $instance_name => $instance) {


And I want to delete all tables, cache, variables node entries related to that module while uninstalling module so that I can re-install it.. What extra code I need ?

_homepage_blocks_installed_fields() and _homepage_blocks_installed_instances() are functions reside in homepage_blocks.functions.inc file and I have included this file to my homepage_blocks.module and homepage_blocks.install

2 Answers 2


Are the functions you are calling from your implementation of hook_uninstall() defined in your .module file? If that is the case, those functions will not be found, as the module file is not anymore loaded in memory.

When hook_uninstall() is called, your module will already be disabled, so its .module file will not be automatically included. If you need to call API functions from your .module file in this hook, use drupal_load() to make them available. (Keep this usage to a minimum, though, especially when calling API functions that invoke hooks, or API functions from modules listed as dependencies, since these may not be available or work as expected when the module is disabled.)

  • but its not going inside this homepage_blocks_uninstall() function..
    – Amb
    Apr 5, 2013 at 10:06
  • 1
    is your uninstall function defined in homepage_blocks.install file? Are you sure, you are uninstalling your module, not just deactivating it? Apr 5, 2013 at 10:09
  • yes it is inside homepage_blocks.install file And yes I want to completely uninstall this module.
    – Amb
    Apr 5, 2013 at 10:13
  • @amss Are you really uninstalling the module? In Drupal, disabling a module, and uninstalling it are two different things. Did you visit admin/modules/uninstall, select your module name, and clicked on the form button to uninstall it?
    – apaderno
    Apr 5, 2013 at 10:24
function homepage_blocks_uninstall() {
    $query = db_select('node','n');
    $query->fields('n', array('nid'))
            ->condition('type', 'homepage_blocks')



I think it will work or u can implement this by batch process also... :)

Your Answer

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

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