I have a module job_post which installs job_post content type.
In this module I have hook_unistall() which calls for node_type_delete() function which removes my content type.
After unistalling process I have errors from Drupal’s core module comment which fires from node_type_delete() after module_invoke_all('node_type_delete', $info).
Error is the following and repeats 8 times (because of the loop in comment_node_type_delete()):
Notice: Trying to get property of non-object in comment_node_type_delete()
(line 343 of ....\comment.module).
I have this error because $info variable in node_type_delete() function is false.
My question is, why when my module is installed and when I’m printing var_dump(node_type_get_type('job_post')) on any page, I have an object, but when I’m trying to print the same code in my unistall function I get false and this error?
job_post.install
/**
* Implements hook_install().
*/
function job_post_install() {
node_types_rebuild();
$types = node_type_get_types();
node_add_body_field($types['job_post']);
$body_instance = field_info_instance('node', 'body', 'job_post');
$body_instance['type'] = 'text_summary_or_trimmed';
field_update_instance($body_instance);
}
/**
* Implements hook_uninstall().
*/
function job_post_uninstall() {
$instances = field_info_instances('node', 'job_post');
foreach ($instances as $instance_name => $instance) {
field_delete_instance($instance);
}
// Force rebuild of the node type cache
// as Clive suggested didn't help
// _node_types_build(TRUE);
node_type_delete('job_post');
field_purge_batch(1000);
}
job_post.module
/**
* Implements hook_node_info() to provide our job_post type.
*/
function job_post_node_info() {
return array(
'job_post' => array(
'name' => t('Job Post'),
'base' => 'job_post',
'description' => t('Use this content type to post a job.'),
'has_title' => TRUE,
'title_label' => t('Job Title'),
'help' => t('Enter the job title and job description')
)
);
}
/**
* Implement hook_form() with the standard default form.
*/
function job_post_form($node, $form_state) {
return node_content_form($node, $form_state);
}
Note: This module example was taken from Pro Drupal 7 Development book (page 141) with minor changes and it was given errors even with original.
Hi by referring to documentation an core modules of Drupal 7. There is a usage problem.
hook_node_info defines a content type automatically. The content types which are created in this way, uninstalled-disable automatically.
Core blog module defines hook_node_info but does not operate any node_type_delete on hook_uninstall
http://api.drupal.org/api/drupal/modules%21blog%21blog.module/function/blog_node_info/7
When you call
node_type_delete('job_post');on hook_uninstall, node type info has already gone. Because of that comments module raises error.Normally you should only remove any data related to your content type. And let the rest to be done by core.
Additionally if you really want create/delete your content type, you may not use hook_node_info. You can manually create/delete content type on install/uninstall hook.
Sample uninstall here:
http://public-action.org/content/drupal-7-field-api-drupal-7-adding-custom-content-type-custom-fields-field-api