Many modules (organic groups forums for one) use taxonomy_save_term() in order to add taxonomy terms (and maybe vocabularies). It would be good if the domain_taxonomy module implemented hook_taxonomy() in order to assure that sensible defaults are set for such situations, otherwise terms can "disappear" after being created, or need to be maintained manually.
I noted that there are form alterations for the core forums along with some core taxonomy editing. But, given the ease with which any module can create terms, it seems like an endless chore to attempt to modify every form properly.
Here is some proposed code that I added to taxnonomy_domain.module. This is definitely not a proposal for commit, but works properly on my site for solving problems in having og_forums used across multiple domains:
// hook_taxonomy()
// Assures that programmatically inserted taxonomy items inherit settings from their parent.
function domain_taxonomy_taxonomy($op, $type, $object) {
$tid = $object['tid'];
if (empty($tid) || $op != 'insert') {
return;
}
$term = taxonomy_get_term($tid);
if (isset($term->domain_source) || isset($term->domains)) {
return;
}
$parents = taxonomy_get_parents($term->tid);
if (count($parents) > 0) {
$parent = array_shift($parents);
domain_taxonomy_load_term($parent);
$term->domains = $parent->domains;
$term->domain_site = $parent->domain_site;
$term->domain_source = $parent->domain_source;
domain_taxonomy_save_term($term);
}
}
| Comment | File | Size | Author |
|---|---|---|---|
| #21 | domain_taxonomy-522016-21-free-tagging-workaround.patch | 4.78 KB | alan d. |
| #8 | domtax_nodecreate_10rc1.patch | 1.83 KB | garywiz |
Comments
Comment #1
garywiz commentedApologies. The code above needs to check if $type == 'term', and probably needs testing. I wasn't proposing this is great code, just giving a sample. If this is useful, I think it needs to be extended to cover the creation of terms with no parent as well, perhaps, as vocabularies.
Comment #2
garywiz commentedContinuing this little conversation with myself...
The above code is somewhat of an over-simplified view. I've modified the module quite a bit at this point, and decided that the best behavior is:
I've implemented this, and it seems to do the trick. But, I don't post the code yet here as we will be doing a lot more site testing and I'd like to be sure it works throughout our test cycle.
I also took a stab at implementing views support, but there are some gotchas. Specifically, this module unconditionally rewrites term_data SQL code to exclude items not available on the current domain. The utility of views, however, is to allow views to be constructed where the availability is a filter (so you can show, for example, forums on affiliated sites as a teaser promo).
I'll wait to see what the module maintainer thinks of this, and maybe I'll put together a patch, but at this point it seems that there may not be much demand for this.
Comment #3
matisse commentedHi garywiz,
I'm a newcomer to Drupal and PHP. I have a problem which I *think* might be related to what you describe.
I'm using Domain Access to create multiple sites from a single Drupal instance and codebase. The sites have different content and I use Domain Taxonomy to categorise content. So on the form to create a new page on site X, I have a "category" input field which dynamically shows me terms already in the taxonomy for that site, e.g. I type "S" and it prefills "Schools". However, when I type a new value (e.g "Churches") although this gets added to the taxonomy, the domain access isn't set. So if I added pages for three "Churches", I'd end up with three "Church" categories, none of which is assigned to any domain. I can get around this by setting the domain manually for each new term as I add a page, but it's cumbersome.
I'm not sure if this is the same issue as yours...?
Comment #4
garywiz commentedYes I think this is the same issue.
Our fix is working for us, but it is cumbersome for many reasons and we find ourselves constantly going in and tweaking things. But, the basic problem you have is one that I believe we have fixed. Whenever we add new nodes, they are properly assigned taxonomy terms as requested, and those terms are assigned to the domain where the addition occured.
The cumbersome issues occur because
The list goes on and on. I really think the whole Domain Taxonomy module needs to be scrutinized heavily to determine an easier and more reliable way to accomplish these goals.
I don't see a lot of activity from the maintainer. If he/she is not active anymore, I'd consider taking over the module or at least contributing some fixes, as we use it heavily. But, that is a lot of work and I won't have the time for a month or two.
Comment #5
matisse commentedHi garywiz,
Thanks for taking the time and trouble to reply. I've just added your function to my taxnonomy_domain.module, wrapping the body in
if ($type == 'term'){}It's not working for me as it stands, but I suspect that may be because my vocabulary is top level, so no parent to inherit from (so covered by your caveat in #1 above). I'm still getting to grips with Taxonomy, and it had occurred to me that perhaps my categories shouldn't be top level terms, so possibly I'd kill two birds with one stone if I go down that route.
You mention above you've changed the module quite a bit. If you could post your latest version, that would be great. I'll keep you posted when I've had a chance to investigate. (I'm tied up in an important doll's house project for Santa Claus at the moment.)
Happy holiday!
Comment #6
garywiz commentedI will create an patch based upon my current implementation, which is working quite well. But, it may be a day or two.
Comment #8
garywiz commented[ ... two "programmer days" later ... ]
Here is a patch which formalizes my original patch and has been fairly well tested (we have been using the code for about 4 weeks on an active site). It assures that any taxonomy items which are created programmatically will have proper domain settings, and also captures domain settings for nodes which are created, then assures that those are applied to taxonomy terms which are assigned as part of the node creation process.
By default, created taxonomy items inherit from their parent (so make sure those are right). But, in the case of terms created during node creation, the node settings will override the term parent, which seems correct to me at least.
This patch is for 1.0-rc1.
Comment #9
garywiz commentedI have re-categorized this as a bug, since having taxonomy terms stranded with no domain affiliation when domain-specific nodes are created renders the taxonomy unusable. I also updated status to "needs review" as there is a beta-level patch available.
Comment #10
Ghostthinker commented+1 #8 tested, seems ok
Comment #11
davemybes commentedWell, if I had just read a bit further into the issue queue, I would have found this patch and saved myself 4 hours of useless coding! Doh! I have tested this on a tags vocab and it works perfectly. Thanks very much, garywiz.
Comment #12
digitalfrontiersmediaI just did a brief test of #8 and it seems to work in my use case as well.
Comment #13
Encarte commentedI applied the patch to the last 6.x-1.x-dev from 2011-Oct-06 (patches should always be against the latest dev) and it worked fine.
Upgrading to major since this bug seriously affects the expected behaviour.
Comment #14
alan d. commentedDoes this effect 7.x branches too?
Comment #15
Nick Lewis commentedThanks Garywiz, and sorry for the delay everyone. Committed to 6.x.1.x dev.
@Alan D. - no this patch won't work with D7, as hook_taxonomy disappeared. This bug is still active (as far as I know) in D7.
Comment #16
alan d. commentedCurrently our local system is a mess, but we can not pin-point the cause (I have yet to investigate).
We had a junior programmer import the terms, about 6000, 8 months back, and he managed to break about everything he touched. Then we have had constant data entity by multiple users. Six months ago we added Domain Access, followed by Domain Taxonomy about 1 month ago and haven't really though about it since till today. Now we wondering how / where duplicates are being generated, issues with merging / editing these, lack of domain settings, .... So just trying to track the status of potential causes :)
If I find anything specific to DA Taxonomy, I will report back.
Comment #17
alan d. commentedSome progress - starting with the duplicate terms that arise if tagging with a term that exists but is not accessible due to DA restrictions, then move it into existing terms that are not currently tagged to the domain.
I have really no idea of the options of this module, so these will need check and modified. For the widget to work, the term must be accessible on the domain that it is being added to BEFORE field validation.
During validation, Taxonomy does this if the term can not be loaded:
And this gets processed in taxonomy_term_save().
I could not get PHP 5.2 to update the term object from any of these hooks. So I could not update 'autocreate' term id here. This is kinda bung as it means we loss a global location for doing this.
Stepping back from the save & presave hooks, the next (almost) global location was the widget itself. So I have added a new #element_validate that checks for duplicates before 'autocreate' is appended. If found, these are shared to the current domain and any entity domains.
Data is saved using HOOK_taxonomy_term_ACTION() hooks.
Cons: Only targets this widget and if the form doesn't validate and the term is latter removed, the term is added to this domain.
I was so expecting a 2 or 3 LOC for this, this is a nightmare!
Comment #18
Nick Lewis commentedAlan,
I feel your pain. It's not going to be a 2 or 3 lines of code change. Most of this module's weirdness seems to be a byproduct of how we Drupaled in 2006. It's telling the only patches I've applied since maintaining this module have been to 6.x versions...
You are touching a much larger issue, imo. This module simply isn't built or Drupal 7. Sure, it doesn't whitescreen, and sort of works, but its ways of doing things are old enough to be in kindergarden by now.
If you make a patch that I can apply to 7.x-3.x dev geared towards the sensible goal of using Drupal's "modern" API, I'll release a 7.x-4.x dev version for the purpose of moving it forward. Be sure to mark the issue as critical if you do, of course.
Comment #19
alan d. commentedTo date, no issues. This is a fairly independent piece of code to tack into the module. (The missing delete is simply an oversight and has no bearing on this issue at hand, couple mis-placed int's in a table isn't going to hurt).
Since there are really no other front end field types, this resolves the front end issues afaict, but my knowledge is limited to - "somethings broke, shit cores f'ed - saving early in presave, how to bypass core without disabling query access, eureka validation, shit core validation kicked into action, validation plan two, assign domains during validation".
I guess if someone tries to commit a term, then there is no reason not to add it. I think that this is cleaner than starting to tag globals or hidden form elements.
Guessing admin related task should be much easier, move away from the additional submission handlers and just let the above code do its thing (if I have the constants, defaults, etc right)
Comment #20
Nick Lewis commentedAlright, could you send me a zip of your version? Happy to make a diff myself.
email is nick (at) chapterthree.com
Comment #21
alan d. commentedComment #22
alan d. commentedThis really is not in a state to commit - the entity hooks will be run twice (but that was a sacrifice that we were willing to undertake on this project due to time restrictions).
Comment #23
Nick Lewis commentedThis looks like a great start. Just curious: what's with all the checking for domains being set? (shouldn't at least one always be set?)
Comment #24
Nick Lewis commentedAnswered my own question after submitting (the disable domain rules per vocab rule....)
Comment #25
alan d. commentedRemember I was guessing at some of the functionality here.
After skimming the start of this thread, have I hijacked the general issue here by extending the scope past programmatically created terms to include free tagged terms. Guessing that this is going to be the most complex use-case, so why not start with the hardest bit :)
I think that domain_taxonomy_taxonomy_term_insert / update() need the most work, so if the domain options are not present, and that these can not be loaded, then to update the term with the modules default DA options.
Comment #26
skizzo commentedIn D7, would "Domain Access Taxonomy" be better in this respect?
Should the two modules be unified?
Please consider http://drupal.org/node/1520062
Comment #27
pascalmortier commented#21 works for me, thx !