Note that there are some explanatory texts on larger screens.

plurals
  1. PODrupal node_type_get_type() and hook_uninstall()
    text
    copied!<p>I have a module <code>job_post</code> which installs <code>job_post</code> content type.</p> <p>In this module I have <code>hook_unistall()</code> which calls for <a href="http://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_type_delete/7" rel="nofollow"><code>node_type_delete()</code></a> function which removes my content type.</p> <p>After unistalling process I have errors from Drupal's core module <code>comment</code> which fires from <a href="http://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_type_delete/7" rel="nofollow"><code>node_type_delete()</code></a> after <code>module_invoke_all('node_type_delete', $info)</code>.</p> <p>Error is the following and repeats 8 times (because of the loop in <code>comment_node_type_delete()</code>):</p> <pre><code>Notice: Trying to get property of non-object in comment_node_type_delete() (line 343 of ....\comment.module). </code></pre> <p>I have this error because <code>$info</code> variable in <a href="http://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_type_delete/7" rel="nofollow"><code>node_type_delete()</code></a> function is <code>false</code>.</p> <p>My question is, why when my module is installed and when I'm printing <code>var_dump(node_type_get_type('job_post'))</code> 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?</p> <p><strong>job_post.install</strong></p> <pre class="lang-php prettyprint-override"><code>/** * 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 =&gt; $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); } </code></pre> <p><strong>job_post.module</strong></p> <pre class="lang-php prettyprint-override"><code>/** * Implements hook_node_info() to provide our job_post type. */ function job_post_node_info() { return array( 'job_post' =&gt; array( 'name' =&gt; t('Job Post'), 'base' =&gt; 'job_post', 'description' =&gt; t('Use this content type to post a job.'), 'has_title' =&gt; TRUE, 'title_label' =&gt; t('Job Title'), 'help' =&gt; 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); } </code></pre> <p><strong>Note:</strong> This module example was taken from <a href="http://www.apress.com/9781430228387" rel="nofollow">Pro Drupal 7 Development</a> book (page 141) with minor changes and it was given errors even with original.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload