Hi,
I am trying to use the views filter "Domain Source: Domain Source ID" in order to only show nodes which have the "current domain" specified as their "source".
The problem: only nodes which have "source domain" explicitly set to the current domain are listed in the view; nodes which have the source domain set as "Use active domain" are not listed!
The domain_source table in the database contains "-5" for all nodes using "Use active domain"; the condition in the views query only checks for the actual domain id:
SELECT [...] FROM {node} node [...]
LEFT JOIN {domain_source} domain_source ON node.nid = domain_source.nid [...]
WHERE [...] (domain_source.domain_id IN ('4') [...]
In the case of filtering by "current domain", I would expect the filter to be domain_source.domain_id IN ('4', '-5').
Comments
Comment #1
bforchhammer commentedAttached patch fixes the issue described above.
Comment #2
bforchhammer commentedComment #3
bforchhammer commentedImproved php-docs.
Comment #4
agentrickardA couple of questions here:
* Is hook_views_pre_build() better than using a query() method?
* Don't the tables need to be aliased in domain_source_views_pre_build()?
Comment #5
bforchhammer commentedI'm assuming you mean a query() on a respective filter handler? Yes, that would probably work as well, but it would mean a custom filter handler class (I think), or an adjustment of the generic filter handler provided by domain_views. The hook implementation seemed like the easier solution.
Hm, you're probably right. For me both values were the same...
Comment #6
agentrickardI think the query() method on the filter object is "better", so we should try that.
Aliasing is definitely required.
Comment #7
planctus commentedthe patch didn't fix the problem for me...
Actually this is really critical for me, i had to teach my client to set the domain source manually, otherwise the website was out of control...
I'll try to see where the problem originates in my installation, but it's a bad time for this to happen..
Thanks,
Da.
Comment #8
bforchhammer commentedI'll have another look at this after drupalcon...
Comment #9
planctus commentedSorry, i'm still trying to figure out how this could happen, but i've totally misunderstood the way domain_source works and this issue consequently, since i used domain access so many times...
My problem was the opposite, anyway..i wanted to filter nodes basing on the domain_source value, but i used the "use active domain" as it would mean "set the active domain during the node creation as the source domain" but it works differently, now i see...
I must say it is pretty ambiguous, but that's a different story.. :)
So, forget my previous comment..
Thanks,
Da.
Comment #10
ParisLiakos commentedI just had the same problem, took me a while to figure out as well.
I think the behavior was different on 6.x or am i wrong?
I think it makes much more sense to store the domain that was used when creating the node..
If "use active domain" is something like a wildcard, there is no point creating an entry in the database for this node, right?
Comment #11
bforchhammer commentedAttached new patch overriding the query method as per #6. Identical In terms of functionality.
Comment #12
agentrickardWhy is this in the patch?
And we have to register the new handler IIRC.
Comment #13
bforchhammer commentedSorry, I removed the files[] array because you actually only have to register files containing classes or interfaces (see docs); that should probably go into a separate issue/patch.
The handler is registered in
domain_source_views_data(), and added to the files[] array. Should be enough afaik, no?Attached patch restores the removed files[] statements and fixes empty lines at the end of files.
Comment #14
agentrickardMy understanding -- and tests have proven it -- is that you have to include files[] for anything that registers a hook as well. The link above is broken.
Comment #15
bforchhammer commentedFixed the link above. This is the relevant bit of text:
Comment #16
agentrickardCommitted to 7.x.3.
Comment #17
agentrickardPushed to 7.x.2.
Comment #18
agentrickardCommitted to 6.x.2.
Comment #19
bforchhammer commentedWonderful, thanks Ken :)