The function category_get_parents doesn't return parents for containers, but only for categories. This causes the category hierarchy to be broken, namely the TOC doesn't display correctly. It also prevents the correct setting of breadcrumbs in the cat_breadcrumb module.
You can realize what happens if you add some debugging code into the function (in category.inc), turning it from this:
else {
$parents[$parent->child][] = $parent;
}
}
}
return $distant ? (isset($distant_parents[$cid]) ? $distant_parents[$cid] : array()) : (isset($parents[$cid]) ? $parents[$cid] : array());
to this:
else {
$parents[$parent->child][] = $parent;
}
}
}
$debug = var_dump($parents[$cid]);
t($debug);
return $distant ? (isset($distant_parents[$cid]) ? $distant_parents[$cid] : array()) : (isset($parents[$cid]) ? $parents[$cid] : array());
If you then visit a container page, you'll get this var_dump output:
NULL
array(1) {
[0]=>
object(stdClass)#83 (9) {
["cid"]=>
string(1) "5"
["cnid"]=>
string(1) "4"
["description"]=>
string(0) ""
["weight"]=>
string(1) "0"
["depth"]=>
string(1) "0"
["child"]=>
string(1) "9"
["title"]=>
string(5) "Test Category"
["admin_title"]=>
string(5) "Test Category"
["hidden_cont"]=>
NULL
}
}
array(1) {
[0]=>
object(stdClass)#88 (9) {
["cid"]=>
string(2) "11"
["cnid"]=>
string(1) "0"
["description"]=>
string(0) ""
["weight"]=>
string(1) "0"
["depth"]=>
string(1) "0"
["child"]=>
string(2) "13"
["title"]=>
string(14) "Test Container"
["admin_title"]=>
string(14) "Test Container"
["hidden_cont"]=>
string(1) "0"
}
}
while with a category you get something like this:
array(1) {
[0]=>
object(stdClass)#25 (9) {
["cid"]=>
string(1) "4"
["cnid"]=>
string(1) "0"
["description"]=>
string(0) ""
["weight"]=>
string(1) "1"
["depth"]=>
string(3) "-10"
["child"]=>
string(1) "6"
["title"]=>
string(11) "Test Category 2"
["admin_title"]=>
string(11) "Test Category 2"
["hidden_cont"]=>
string(1) "1"
}
}
array(1) {
[0]=>
object(stdClass)#25 (9) {
["cid"]=>
string(1) "4"
["cnid"]=>
string(1) "0"
["description"]=>
string(0) ""
["weight"]=>
string(1) "1"
["depth"]=>
string(3) "-10"
["child"]=>
string(1) "6"
["title"]=>
string(11) "Test Category 2"
["admin_title"]=>
string(11) "Test Category 2"
["hidden_cont"]=>
string(1) "1"
}
}
array(1) {
[0]=>
object(stdClass)#21 (9) {
["cid"]=>
string(1) "1"
["cnid"]=>
string(1) "0"
["description"]=>
string(0) ""
["weight"]=>
string(1) "0"
["depth"]=>
string(1) "0"
["child"]=>
string(1) "4"
["title"]=>
string(21) "Hidden Root Container"
["admin_title"]=>
string(21) "Hidden Root Container"
["hidden_cont"]=>
string(1) "1"
}
}
Basically what this means is that, since there is that NULL there in the container var_dump output, when you call isset($parents[$cid]), the function evaluates to true for categories and thus returns the parents correctly, while for containers the function evaluates to false and thus returns an empty array (the array() mentioned).
I do not know if this was done by design, but I do know it breaks the TOC and makes it impossible to set breadcrumbs properly for containers.
I tried fixing it myself, but I couldn't find a way, so any input is appreciated.
Comments
Comment #1
Permanently Undecided commentedThis has been fixed in the 5 Jan official releases, both of 4.7 and 5.0.
Comment #2
Permanently Undecided commented