1

I'm quite new with Drupal 7 development, after researching and following some tutorials I was able to create my custom module that defines a new node type with some fields, but now I have a problem when I uninstall it, the hook_uninstall runs almost fine(the node type, the contents from my custom node, and the node fields), except that display this error after the uninstall:

Notice: Trying to get property of non-object en comment_node_type_delete() (línea 344 de /opt/lampp/htdocs/drupal/modules/comment/comment.module). Notice: Trying to get property of non-object en comment_node_type_delete() (línea 355 de /opt/lampp/htdocs/drupal/modules/comment/comment.module). Notice: Trying to get property of non-object en comment_node_type_delete() (línea 355 de /opt/lampp/htdocs/drupal/modules/comment/comment.module). Notice: Trying to get property of non-object en comment_node_type_delete() (línea 355 de /opt/lampp/htdocs/drupal/modules/comment/comment.module). Notice: Trying to get property of non-object en comment_node_type_delete() (línea 355 de /opt/lampp/htdocs/drupal/modules/comment/comment.module). Notice: Trying to get property of non-object en comment_node_type_delete() (línea 355 de /opt/lampp/htdocs/drupal/modules/comment/comment.module). Notice: Trying to get property of non-object en comment_node_type_delete() (línea 355 de /opt/lampp/htdocs/drupal/modules/comment/comment.module). Notice: Trying to get property of non-object en comment_node_type_delete() (línea 355 de /opt/lampp/htdocs/drupal/modules/comment/comment.module).

This is from mymodule.install:

function mynode_uninstall() {

    $ournewtype = 'mynode';
    $sql = 'SELECT nid FROM {node} n WHERE n.type = :type';
    $result = db_query($sql, array(':type' => $ournewtype));
    $nodeids = array();
    foreach ($result as $row) {
        $nodeids[] = $row->nid;
    }
    node_delete_multiple($nodeids);
    node_type_delete($ournewtype);
    field_purge_batch(500);
    drupal_flush_all_caches();
}

1 Answer 1

1

I believe the problem is that it's expecting an object, and you are passing a string. Try changing this:

node_type_delete($ournewtype);

To this:

$node_type = node_type_load($ournewtype);
node_type_delete($node_type);

One other thing, instead of this:

$result = db_query($sql, array(':type' => $ournewtype));
$nodeids = array();
foreach ($result as $row) {
    $nodeids[] = $row->nid;
}

You can simplify it by using this:

$nodeids = db_query($sql, array(':type' => $ournewtype))->fetchCol();
3
  • Thanks for your suggestion, tested but the error still persist. Jul 16, 2017 at 2:02
  • Also, with that modification, hook_uninstall doesn't delete the node type and node fields. Jul 16, 2017 at 2:04
  • I believe that the problem si because node_type_load doesn't load if because the module is already disable and thats why doesn't delete the node type, but i'm not shure, still quite new in this stuff. I wasn't able to fix it. Jul 18, 2017 at 13:05

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.