As a user, I am not sure how to use the "Domain Argument" in Views, so I am using "Domain Filter" which was easier to grasp.
1) Argument: adding few usage examples in Domain Views readme would clarify the meaning of "Default, Title, Wildcard, Wildcard Sub"
2) Filter: would it be possible to have the View use the current domain when no Value is selected from the filter dropdown?
This condition currently results in SQL warning.

Comments

agentrickard’s picture

I don't necessarily grasp the arguments bit, either.

For #1 see the Views Arguments documentation at http://drupal.org/node/99566.

For #2, I don't know. This may be a bug. I think filters require that something be selected. Arguments can be set to use default values.

mrichar1 wrote the module, so perhaps he will comment.

mrichar1’s picture

For #1: http://drupal.org/node/54455 is the user documentation for views arguments, agentrickard's link was the developer documentation. The documentation contains examples, but this is how I use it:

Given a page view with the url set to "cars" that shows a listing of all nodes of node-type "car", if I enable the "Domain Access" argument type and go to www.mysite.com/cars/3 I will see a listing of all nodes of type car that are assigned to domain 3.

Additionally, if you paste the following code to the "Argument Handling Code" (http://drupal.org/node/70145) text box then the view will automatically use the id of the current domain as the filter

// Make the first argument "current" if it is not already set
if (!$args[0]) {
  $args[0] = 'current';
}
return $args;

FYI, I don't use any of the "Default, Title, Wildcard, Wildcard Sub" options myself, but I did add the appropriate code and test it to make sure that the summary views work....didn't test title or wildcard though.

For #2: For the filters, I used the simplistic approach that views provides for creating a filter without providing a handler, unfortunately it doesn't seem to include any provisions for dealing with the case where no values are selected. This could be addressed by writing a custom handler for the filter.

I had originally planned to use the filter to do exactly what you mentioned, filter by the current domain, but I soon discovered that the views modules was caching the query that was generated and decided to take the "arguments" approach instead. However in researching this issue I just realized that there are two other options that might make this work, either by using hook_views_query_substitutions (http://drupal.org/node/99567) or by setting cacheable=no on the filter (http://drupal.org/node/99794). The views module uses the hook_views_query_substitutions approach for showing "nodes that were created by the current user".

I am not sure which one of these options is more performant, but I do plan on looking into. Unfortunately I won't be able to look at it this week which means I won't be able to look at it this year (I go on vacation next week). I'll make a note to get back to this when I come back if someone else hasn't already addressed it.

P.S. agentrickard, could you create a component for Domain Views so that I can subscribe to its RSS feed?

skizzo’s picture

Re #2, having the filter by-current-domain would make a huge difference: in my case it would mean one single view, against N views (one per domain). So I will stay tuned hoping that a solution can be found, meanwhile I want to thank you for going through the long explanation. Enjoy your holyday!

mrichar1’s picture

skizzo, you can actually get what you are looking for right now by adding the Domain Access argument and pasting the following code to the "Argument Handling Code" text box

// Make the first argument "current" if it is not already set
if (!$args[0]) {
  $args[0] = 'current';
}
return $args;
agentrickard’s picture

Component: Code » - Domain Views

Done.

I would love some simple documentation we could add to the README as well.

mrichar1’s picture

You can replace the "Arguments" section of the README with the text below.

-----------------------------------------------------------------------------------------------------------------------------------------------------------

3. Arguments

This module provides a Domain Access argument that can be added to any View. Arguments can be thought of as "dynamic filters" that are applied to the view at run-time.

It currently accepts two types of arguments, (1) a numrical domain_id (2) the string "current". Assume we have page view that shows a listing of all nodes of node-type "car", and you enable the "Domain Access" argument type:

If you go to www.mysite.com/cars/3 you will see a listing of all nodes of type car that are assigned to domain 3.

If you go to subdomain4.mysite.com/cars/current you will see a listing of all nodes of type car that are assigned to subdomain4.

If the argument value is not set in your View, it will display the default view which can be "page not found", a summary view or any of the other defaults.

You can get the view to filter by the current domain by default by pasting the following code in "Argument Handling Code" text box . This will cause the view to always see the id of the current domain as first argument if no argument has been passed in.

// Make the first argument "current" if it is not already set
if (!$args[0]) {
$args[0] = 'current';
}
return $args;

For more on Views Arguments, see the documentation on argument handlers for views at http://drupal.org/node/54455.

-----------------------------------------------------------------------------------------------------------------------------------------------------------

N.B. The following statement that is currently included in the README.txt is incorrect.

If the argument value is not set in your View, it will automatically use the currently active domain.

derjochenmeyer’s picture

$args[0] = 'current'; this is so essential that it could also go as the Agument description!

'help' => t('Set Argument Handling code to $args[0] = "current"; to filter by current domain. For More information read the README.txt provided in the module directory.'),

Arguments still confuse me. Im sure new useres have no idea where to start. And they often dont read documentation. So why not put that superusefull information right there?!

agentrickard’s picture

Status: Active » Fixed

Added comment #6 and a note about Views filters to the README, thanks.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.