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.
Hello,
Regarding hook_update and hook_insert :
The existing check on the term parent is:
if (empty($term->parent)) {
But when the term doesn’t have a parent, the value of $term->parent is: array(‘0’ => ‘0’) so the check passes when it shouldn’t and the processing goes on.
If there is a parent, the value of $term->parent is: array('[Tid-parent]' => '[Tid-parent]’).
My proposal is to modify the existing check to be:
if (array_keys($term->parent) == array(0)) {
That would prevent the massive impact on performance while importing a lot of stand-alone terms.
DrDam
Comment | File | Size | Author |
---|---|---|---|
shs-empty-condition.patch | 786 bytes | DrDam |
Comments
Comment #1
DrDam CreditAttribution: DrDam commentedComment #2
stBorchertYes,
empty()
does not check for the parent beingarray(0 => 0)
here.But that's on purpose. A cache update with "parent = 0" (which equals to "no parent at all") is required.
If I would skip updating when you insert/update a term without parents, would not work anymore as it was intended to, because the top-level list of terms within the hierarchy would not be cached.