Categories with multiple parents (in multiple hierarchy containers) are not correctly rendered in category selects, but are shown only under the first parent. This is because #options arrays -- as they are still used by the Category module -- can't contain a key twice (see this issue).
This issue can't be solved as long as #options are represented as simple arrays. Therefore #options in taxonomy arrays are represented as objects instead, starting with Drupal 5.x (see Converting 4.7.x modules to 5.x.
I suggest switching to the representation of #options as objects to solve this issue and to keep emulating core taxonomy.
print_r($form['category']) (with category.module enabled)
Array
(
[#type] => fieldset
[#title] => Categories
[#collapsible] => 1
[#collapsed] => 1
[#tree] => 1
[158] => Array
(
[#type] => select
[#title] => Testcontainer
[#default_value] => 0
[#options] => Array
(
[0] => <none>
[159] => Testcategory 1
[160] => Testcategory 2
)
[#description] =>
[#multiple] => 0
[#size] => 0
[#required] => 0
[#weight] =>
)
)
print_r($form['taxonomy']) (with category.module disabled)
Array
(
[158] => Array
(
[#type] => select
[#title] => Testcontainer
[#default_value] => Array
(
)
[#options] => Array
(
[0] => <none>
[1] => stdClass Object
(
[option] => Array
(
[159] => Testcategory 1
)
)
[2] => stdClass Object
(
[option] => Array
(
[160] => Testcategory 2
)
)
)
[#description] =>
[#multiple] => 0
[#size] => 0
[#weight] => 0
[#theme] => taxonomy_term_select
[#required] => 0
)
[#weight] => -3
[#tree] => 1
)
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | activeselect.js_.patch | 694 bytes | bdragon |
| #4 | category-activeselect-multiple-fix.patch | 1.84 KB | bdragon |
| #2 | category.module_2.patch | 1.35 KB | pancho |
| #1 | select_0.patch | 858 bytes | bdragon |
Comments
Comment #1
bdragon commentedPlease test this patch and check for side effects.
Comment #2
panchoSeems to work perfectly! Tested it on regular and tweaked node forms - the #options behave now exactly like taxonomy.module and correctly render multiple hierarchy terms.
As your patch will break the "category_activeselect" function, I updated that one, too. Enclosed is a combined patch - please check this as well though my obj2arr conversion code has been tested positive!
Actually activeselect seemed to me already broken before patching this issue here -- it didn't get worse... :/
print_r($form['category']) (with category.module enabled)
Comment #3
firstov commentedI'm having similar issue with my travel site I'm working on. When I list all categories in Admin menu I see all parents and all their child terms, however when I try to add new content, I only see a few children terms for some parent terms.
Is there a fix for Druapl 4.7.6?
Thanks!
Comment #4
bdragon commentedOK, I got a chance to look at this a bit.
Here is an (untested!) patch to category.module that should make activeselect + multiple parents work correctly on the Category side. (It requires a patch to activeselect, will be posted in a sec)
Comment #5
bdragon commentedAnd this is the Activeselect side.
Comment #6
panchoI tested your patch under various circumstances and it mostly seems to work. Still there seem to be two problems:
Regards, Pancho
Comment #7
bdragon commentedAhh, so that's the source of the illegal choice bug...
I think we need to bypass the built-in validation and do it ourselves, there have just been too many bugs regarding activeselect and validation.
For my own and others reference, setting $element['#DANGEROUS_SKIP_CHECK'] on a form element will disable builtin validation on the element. We then need to manually sanity check the selected options.
Regarding duplicate entries, taxonomy_term_save is a bit dumb when it comes to writing to term_node. This is another thing that needs a look at...
Comment #8
panchoDon't know if that's the source of all Illegal-choice bugs, as this one is only about activeselects...
I agree, we should go for our own val routine, as we can then also check whether a child term is actually allowed for its parent. This way we could make sure Non-JS users (with an actually not so gracefully degraded activeselect mechanism) don't apply non-sense combinations of terms (such as cat1: "2006", cat 2: "February 2004".
Still, I think FAPI should try to flatten all kinds of elements. This being restricted to selects seems to me more like a quick-fix than a generic solution. Why shouldn't other elementtype's options (e.g. radios) be in object or nested array style? This would ease up rendering catboxes as nested selects, radios or whatever. Think we should get that into 6.0 core.
(When I'm talking about core - do jaza and you have alrady laid out a concrete plan about getting certain parts of category module into core taxonomy?)
Concerning the "duplicate entries" issue - I guess we should leave this to another thread, as this needs to be generally fixed once and for all.
Regards, Pancho
Comment #9
bdragon commentedWithout activeselect, the only way to get an illegal choice is to cheat using the webdeveloper toolbar or some such, in my opinion.
Yep, and by doing that, we only would need one set of logic, no matter if it was an activeselect, select, freetag, or whatever interface.
I'm not sure what you mean here.
I don't personally have any plans yet. Fixing things in core that unreasonably interfere with Category are of course a good idea. I'm really excited about the new menu system, it's going to be great.
Yeah.
--Brandon
Comment #10
John Bryan commentedNOTE to anyone with apparently scrambled taxonomies i.e. Containers. Uninstall "Category" and they should be still intact.
I'm guessing you know all the below bdragon 8¬) it looks like you well past diagnosis. But I never presume as it makes a pre out of u and me - Hmm, well I assume you know what I meant ;¬)
Installed "category-5.x-1.1.tar.gz" and every method of viewing or displaying my 'container' 'categories' was messed up (apart from one, see later). Out of several 'containers' only one was hierarchical multi-parent but not only were some of it's branches apearing off the root of that 'container'... some were appearing in completely different un-related 'containers'!
But if I tried to edit a 'category' to correct the miss-placement the edit screen would show the correct parentages still in place. And when I uninstalled the "Category" module I found that the underlying original taxonomy & terms were still intact and correct.
From some of the documentation I gather a certain duality of data is held with "Category" 'categories' being held in seperate tables but the "Taxonomy" 'terms' being retained and maintained in the original core tables? (or is that complete balderdash on my part)
In which case...
The question is where from and how does the edit category/container 'Categories' selection box read it's data? If it reads it's data from the "Category" 'container' then, at least in my case, the container was working fine - it is the retrieval that is $%!!"£.
Comment #11
John Bryan commentedMy taxonomies do have some damage plus some node are still left as Categories/terms(?) with contents and node family relationships lost.
This blows my location of problem logic out of the water as well as my don't worry just uninstall statement 8¬(
Comment #12
panchoJohn: Please don't give your follow-up comments in the issue tracker system (!) a new title as this will change the title for the entire issue thread!
Otherwise I really didn't get your point (except for: "category.module is buggy"), but I will re-read it until I got it... :)
Comment #13
bdragon commentedHow it works is:
1) Category provides the interface and storage for categories and containers.
2) The taxonomy.module is turned into a "wrapper" that maintains, as much as is possible, a copy of the "terms" (which are really nodes now) in the term_* tables, for the benefit of modules that try to use the term_* tables directly.
If you need to convert stuff back to real terms, category_legacy can do that on a container-by-container basis. You would also use category_legacy to convert old vocabularies into containers and categories.
Comment #14
firstov commentedNot sure why containers got involved in this. It was my understanding the bug is related to some queries in the forms (when you "create new content").
The database structures appear to be working and displaying all parents/children content just fine, when listing all terms for the particular vocabulary.
Again, the bug is when you creating new content and unable to select correct category term.
Thanks.
Comment #15
liquidcms commentedthis ever get sorted out?
I have 4.7 and 5.7 installs of Drupal and category module and neither show a mutliple select for parents when adding a category whose container is set to multiple hierarchy.
Comment #16
jergason commentedIs anyone still working on this?