Throwing some code over the wall (see attached) in case anyone finds it useful.
This code implements views integration for the domain module by adding a views filter and argument handler. This allows you to restrict your view content to only show content from a specified domain (or set or domains) either by using a predefined filter or by passing arguments to the view e.g. mysite.com/myview/6 (where 6 is the id for one one of your domains).
Could be useful if you have content that is assigned to multiple domains but you only what to display modes from a specific subdomain(s) in the current view. As an added bonus if you pass the argument "current" to the view e.g. mysite.com/myview/current it only shows nodes that belong to the current subdomain (by looking at $GLOBALS['_domain']['domain_id']).
We are using that feature + the following argument handling[1] code snippet on our views to work around the "users with the administer nodes permission will see nodes from all domains" issue.
// Make the first argument "current" if it is not already set
if (!$args[0]) {
$args[0] = 'current';
}
return $args;
I developed the code against Beta7 but it should work as long as the domain tables schema hasn't changed and $GLOBALS['_domain']['domain_id'] and domain_domains() are still the same.
The code implements the views_tables() and views_arguments() hooks and includes one handler function used by the views_arguments() hook.
I didn't bother creating a patch since it doesn't modify any other functions and I am very lazy. Right now I just have these functions sitting at the bottom of domain.module file. It would be great if they eventually made their way into the official module.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | domain-views2.txt | 3.55 KB | mrichar1 |
| domain-views.txt | 3.39 KB | mrichar1 |
Comments
Comment #1
agentrickardInteresting. I haven't played with Views enough, but I received a similar request for MySite recently.
The API fundamentals have not changed -- though the 'valid' flag on each domain which might need to be checked before applying the filter.
I am also about to commit some code that, ironically, does the reverse of this filter.
In some cases, you want all nodes in a View to be visible regardless of the active domain. (Take the 'popular/alltime' view for example). There is now a DA 'Special pages' setting that lets you specify paths on which to ignore DA rules.
I think the best approach for this snippet is to make it an optional Domain Views module. Then people can turn it on and off.
If you don't want to maintain that, I'll see about adding it to the release.
Marking as a patch, even though it isn't, really.
I think the Skirt folks will love this.
Comment #2
agentrickardYou also get a prize for being the first person to exploit $GLOBALS['_domain']['domain_id'] AFAIK.
Comment #3
mrichar1 commentedLet me just clarify something, right now we are primarily using this to work around the "users with the administer nodes permission will see nodes from all domains" issue. That other use case I mentioned is untested and may be completely made up.
However from a quick test I did it seems that you could make use of this feature in the following way.
Lets say we have 10 nodes, 5 are assigned (published) to domain1 and 5 are assigned (published) to domain2, but all 10 have the "Send to all affiliates" box checked as well. If you were looking at a view of all these nodes on domain1 you would see all 10, but if you wanted to restrict it to only show the nodes that "belonged" to domain1 (or domain2) you could use the views arguments filter...
Not sure if this makes sense. I am kinda making it up as I go along. Maybe someone will find use for this behaviour.
Comment #4
mrichar1 commentedI have updated the "patch" to make a check for the 'valid' flag when generating the summary view. This way a listing won't be shown for inactive subdomains.
As far as I know this shouldn't be an issue for the filtering code since the view should only show you a subset of the things you already have access to, but I could be wrong, I am pretty new to Views and node_access myself.
I appreciate your offering to incorporate this code into the release. I am still a relative drupal newbie and the very thought of having to mess with CVS would make me a very poor maintainer.
Edit: Forgot to upload the file the first time.
Comment #5
mrichar1 commentedResetting status to patch (code needs review). I think I started (but didn't finish) my first comment before you had sent yours so it messed up the status flag.
Comment #6
agentrickardWaiting for a new file to be attached. I did talk to the Skirt.com maintainers; they are excited by this feature.
Comment #7
mrichar1 commentedYeah, sorry about that. I editted comment #4 and attached it.
Comment #8
skizzo commentedI would like to say thank you to mrichar1. Just yesterday I was thinking about using Views alongside with DA, but didn't dare to ask... Not being a programmer, I can only feel good about putting things to use. I am now eagerly waiting for Views support in beta8.
Comment #9
mrichar1 commentedI am glad people are finding a use for this code.
Comment #10
agentrickardCommitted to HEAD. This is awesome, thanks.