Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
function node_type_delete($type) {
$info = node_type_get_type($type);
db_delete('node_type')
->condition('type', $type)
->execute();
field_attach_delete_bundle('node', $type);
module_invoke_all('node_type_delete', $info);
node_type_get_type() does not returns info for a node_type tagged as disabled, it will $info=FALSE. This behavior is due to _node_types_build().
Use of $info=FALSE will make hook_node_type_delete fail.
Typically, node_type_delete is called during hook_uninstall, when the node_type has already tagged as disabled
Comment | File | Size | Author |
---|---|---|---|
#23 | node.test-943588-23.patch | 2.06 KB | pillarsdotnet |
#22 | 943588_node_type_delete_110313.patch | 2.7 KB | jpsoto |
#19 | node_type_delete-943588-13-tests-only.patch | 1.75 KB | bfroehle |
#13 | node_type_delete-943588-13.patch | 2.7 KB | pillarsdotnet |
#12 | 943588_110106.patch | 2.91 KB | jpsoto |
Comments
Comment #1
jpsoto CreditAttribution: jpsoto commentedThis patch should solve the bug ...
Comment #2
sun.core CreditAttribution: sun.core commented#1: 943588_101023.patch queued for re-testing.
Comment #3
jpsoto CreditAttribution: jpsoto commented#1: 943588_101023.patch queued for re-testing.
Comment #4
pillarsdotnet CreditAttribution: pillarsdotnet commentedMarked #995756: Trying to get property of non-object as a dup of this issue.
Comment #5
jpsoto CreditAttribution: jpsoto commented#1: 943588_101023.patch queued for re-testing.
Comment #6
pillarsdotnet CreditAttribution: pillarsdotnet commentedSame patch, minus the name change.
Comment #7
jpsoto CreditAttribution: jpsoto commented@pillarsdotnet, thanks for your review and support ... I think issue status can be evolved.
I described a similar (but different) behavior for fields-related functions: #943772: field_delete_field() and others fail for inactive fields
Comment #8
webchickWe should add tests for this I think.
Comment #9
jpsoto CreditAttribution: jpsoto commented@webchick ... OK, I will add the related tests ... using the last patch #6
Comment #10
pillarsdotnet CreditAttribution: pillarsdotnet commentedTypo in #6; correcting...
Comment #11
pillarsdotnet CreditAttribution: pillarsdotnet commentedComment #12
jpsoto CreditAttribution: jpsoto commentedFriends ... attached you can find the patch including two additional tests: deletion of a node type, and deletion of a disabled node type.
The second test would fail in the present Drupal core, but it is passed using the patch. Local testing has been carried out.
[patch includes the Pillarsdotnet's contributions]
Please, take a look at a other issue, with similar (but different) behavior for fields-related functions: #943772: field_delete_field() and others fail for inactive fields
Comment #13
pillarsdotnet CreditAttribution: pillarsdotnet commentedI understand changing the parameter name away from $type so as to avoid visual confusion with the array $types but calling it "$bundle_name" is also confusing, as it conflicts both with the documentation and with the naming convention used in other, similar functions in core.
How about compromising by calling it $type_name instead of $bundle_name?
Comment #15
pillarsdotnet CreditAttribution: pillarsdotnet commented#13: node_type_delete-943588-13.patch queued for re-testing.
Comment #16
jpsoto CreditAttribution: jpsoto commented@pillarsdotnet, thanks for your suggestions ...
friends, ... ihmo, issue status can be evolved ...
Comment #17
Taxoman CreditAttribution: Taxoman commentedSubscribing.
Comment #18
bfroehle CreditAttribution: bfroehle commentedThere is an extra line between the docblock and the function. Also, I disagree with changing the argument name -- $type is fine and is consistent with other functions (like "node_type_update_nodes($old_type, $type)", for example). But whatever.
Rewrite this using db_update().
Extra white space on this line.
Powered by Dreditor.
Comment #19
bfroehle CreditAttribution: bfroehle commentedAnother bigger problem is that the added tests do not trigger the bug.
Comment #20
bfroehle CreditAttribution: bfroehle commentedComment #21
jpsoto CreditAttribution: jpsoto commented@bfroehle
please, feel free to complete the works ... This bug is open long long time ago and now I am quite busy.
Comment #22
jpsoto CreditAttribution: jpsoto commentedRollback using an updated git diff ... trying testing
Comment #23
pillarsdotnet CreditAttribution: pillarsdotnet commentedTesting-only version of above patch.
(Tests of a bugfix, without the bugfix, should fail)
Comment #24
pillarsdotnet CreditAttribution: pillarsdotnet commentedOnce again, tests pass without the fix, so the tests are not effective.
Comment #25
jpsoto CreditAttribution: jpsoto commented@pillarsdotnet
I beg your pardon ... I am not able to understand what you are suggesting ...
Please, feel free to merge or complete my patch ...
Comment #26
bfroehle CreditAttribution: bfroehle commented@jpsoto: What @pillarsdotnet is saying is that the test routines are not sufficient to trigger the bug. That is, without any patch to Drupal's behavior, all of the test routines pass. Essentially the test routines have failed to trigger the bug, and thus are insufficient.
Comment #27
jpsoto CreditAttribution: jpsoto commentedOK ... now I understand ... thanks.
Let me a couple of days, to setup a sensible test proving the bug.
Comment #28
jpsoto CreditAttribution: jpsoto commentedOK ... after a preliminary review, I have found out a significant change since patch and test codes were written (over six months ago).
Now, when a module (which created a node type) is disabled, such a node type is *not* marked as disabled. Direct DB inspection reveals it; disabled remains FALSE, at least for me.
Seemingly, such a behavior should be not correct because the field "disabled" seems to be used for several tasks.
I am not able to remember if, in October, the field "disabled" were toggled by module_enable() / module_disable(). And my skills to dig into the git log are limited.
Any way, ... this could explain why now the tests are not able to reproduce the bug. Or even more, this could explain why the bug could have disappeared (or rather mutated).
Does anybody know if the field "disabled" of an node type is in use, or is to be removed in the future?
What about closing this issue?
Comment #29
pillarsdotnet CreditAttribution: pillarsdotnet commentedIt looks like this behavior was changed by this commit which came from this patch.
Types which are not provided by hook_node_info() are no longer disabled by node_types_rebuild().
Marking this issue as a duplicate of #986296: _node_types_build() accidentally marks node types as disabled because even though the symptoms are different, the cause (and fix) appear to be the same.
Comment #30
rbruhn CreditAttribution: rbruhn commentedSorry if this is the wrong place to post. I've chased through all sorts of issues about node content being left behind and this seems the closest to what I'm experiencing.
I'm defining a custom node in hook_install() with 'base' => 'bir_collection'. When going through the process of uninstalling, I get errors:
Notice: Trying to get property of non-object in comment_node_type_delete()
This only occurs when base is set to a custom type. If 'node_content' is used, no errors occur when uninstalling. This is due to the node type NOT being set as 'disabled' when base is 'node_content'.
Tracing this back, it can be seen the disabled node type is not picked up in _node_types_build().
Performing tests by calling _node_types_build()->types in a script shows the custom node type is not returned when disabled. So after disabling and trying to uninstall, the $info variable in module_invoke() is empty. Thus, causing the error posted above.
Am I missing something here in my uninstall hook? Should node_type_delete() not be used for node types created in modules?
Edit:
Found #1181030: Node types disabled by _node_types_build() when using node_type_save() with base != 'node_content' speaking about the same issue. Funny, because all these issues link back to one another but the problem still remains.
Comment #31
realguess CreditAttribution: realguess commentedMy solution is that just temporarily enable the node type in
hook_uninstall
, then proceed to delete the node type.Not a solution I like, I think
node_type_delete
should be able pick up the disabled node types. But this will get rid of error messages from other modules that implementshook_node_type_delete
.Comment #32
rbruhn CreditAttribution: rbruhn commented@realguess
Thanks, I will give your solution a try.
Comment #33
duckegg CreditAttribution: duckegg commented@realguess
Good shot! It solves my problem
Comment #34
jonathan1055 CreditAttribution: jonathan1055 commented@pillarsdotnet in #29 - thanks for finding that commit. However, the issue we have here is not actually solved by that fix. Our problem is that implementations of hook_node_type_delete in other contrib modules give errors because the $info parameter passed is empty or null.
I have found an alternative solution to the one from realguess in #31. At the start of hook_uninstall, instead of re-enabling the content type, you can call
The call to node_types_rebuild() will include the disabled content types and the result will be stored in the cache for the remainder of the page requset, thus any further calls to node_type_get_type() will be able to return the info required. I have used this in Weblinks #2500119: Uninstalling produces error: Trying to get property of non-object in comment_node_type_delete() as we had exactly the same problem.
Hope that helps anyone else who comes across this error.
Jonathan