argument.html 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. Contextual Filters (known in previous versions of Views as "Arguments") are input. While they often come from the URL, they don't always. Don't be shocked when they don't. Each display type may have its own source for contextual filters. Block displays have no source of contextual filters at all; they cannot pull contextual filters from the URL, and often require use of PHP code as a default contextual filter. Various default values can be applied against contextual filters to use filters in a block view. See "Provide default value," under "When the filter value is NOT in the URL" below.
  2. In general, contextual filters are used to filter the view, and in that sense they have a very close relationship to filters. However, this isn't necessarily true for every contextual filter. Contextual filters can be used for any purpose, really; the extent of what the contextual filter does is up to the developer of the contextual filter.
  3. A typical use of an contextual filter might be to reduce a view to a single node, a single user, or nodes with a given taxonomy term.
  4. <h3>When the filter value is NOT in the URL</h3>
  5. <dl>
  6. <dt>Display all results for the specified field</dt>
  7. <dd>If this option is selected, the contextual filter is removed from the view as though it weren't there and all results will be displayed.</dd>
  8. <dt>Provide default value</dt>
  9. <dd>If no contextual filter is given, a default contextual filter can be selected. You may choose from a number of different default filter options. See "Default contextual filters" below.</dd>
  10. <dt>Hide view</dt>
  11. <dd>The view will remove itself entirely if the contextual filter is not present; for a block this means it simply won't appear. For page views the view will return a 404 and present a "Page not found" error. </dd>
  12. <dt>Display a summary</dt>
  13. <dd>The view will attempt to display a summary of contextual filters available, based upon the view, and provide links to the view with those contextual filters. Summaries have their own style handlers as well as options. The default summary style simply displays a list of contextual filters with a count of entries found per contextual filter. This special mode is a very powerful part of Views.</dd>
  14. <dt>Display contents of "No results found"</dt>
  15. <dd>If this option is selected, the value specified under "No results behavior" on the main view page will be displayed when there is no filter value in the URL.</dd>
  16. </dl>
  17. An exception value can be set under the "Exceptions" menu. If this exception value is received, any filter value specified under "When the filter value is NOT in the URL" will be ignored. This is a literal value: if you enter the word "everything" here, the exception will apply only if the value "everything" is received.
  18. <h3>Default contextual filters</h3>
  19. The Default contextual filter selection is available <strong>only if the action to take is "Provide default value"</strong> under "When the filter value is NOT in the URL." When that option is selected, a new fieldset will appear that will allow you to choose default contextual filters. Views provides the following default selectors by default (but other modules may add more):
  20. <dl>
  21. <dt>Content ID from URL</dt>
  22. <dd>This will attempt to find a Node ID from the URL, and is primarily useful for the Node: ID contextual filter (though other contextual filters that use Node IDs, such as the CCK Node Reference contextual filter, will find it useful, too). For example, when visiting the path "node/1" or "node/1/edit" it will know that the "1" in that path is a node ID and use it.</dd>
  23. <dt>Fixed value</dt>
  24. <dd>You may directly enter what the contextual filter will be. This is not a variable, it will always be the same contextual filter. </dd>
  25. <dt>PHP Code</dt>
  26. <dd>Arbitrary php code inserted here will run whenever a contextual filter is not present in the URL.</dd>
  27. <dt>Taxonomy term ID from URL</dt>
  28. <dd>This default filter will attempt to return a taxonomy term from the current path. Selecting this option gives you the choice to also load default filters from terms.</dd>
  29. <dt>User ID from URL</dt>
  30. <dd>Like Node ID and Taxonomy term ID from URL, this will attempt to find a user ID from the path. It also includes an option to look for a node and use the node author as the user ID.</dd>
  31. <dt>User ID from logged in user</dt>
  32. <dd>If a user is currently logged in and accessing this view, their user ID will be returned as the contextual filter.</dd>
  33. <dt>Current date</dt>
  34. <dd>This option simply returns today's date.</dd>
  35. <dt>Current node's creation time</dt>
  36. <dd>Select this to return a node's creation time as a contextual filter.</dd>
  37. <dt>Current node's update time</dt>
  38. <dd>Not surprisingly, this filter returns the current node's update time</dd>
  39. </dl>
  40. Please bear in mind that the selection of a default contextual filter happens only if a contextual filter is not provided. If you are using a display that has no contextual filter source, such as a block, the contextual filter value selected here will always be used. However, if using a display that reads contextual filters from the URL, the options selected here will only be applied if the URL did not contain an contextual filter.
  41. The "Skip default argument for view URL" option gives you the choice of ignoring the default argument totally. This is useful for certain applications, like the creation of feeds.
  42. <h3>When the filter value IS in the URL or a default is provided</h3>
  43. <dl>
  44. <dt>Override title</dt>
  45. <dd>Selecting this option will allow you to replace the default view title with a piece of arbitrary text. Argument substitutions in the form of %1, %2, etc. may be used here.</dd>
  46. <dt>Override breadcrumb</dt>
  47. <dd>This option will allow you to overwrite the view name in breadcrumbs. The same substitution values as in "Override title" may be used.</dd>
  48. <dt>Specify validation criteria</dt>
  49. <dd>Contextual filters can have validators, which are pluggable systems used to ensure that contextual filters fit within certain parameters. When a validator is chosen, it may provide some specific settings, including the action to take if an contextual filter is presented, but it fails to validate. These actions are generally the same as the default actions above, excluding the ability to provide another default filter. See "Contextual filter validation" below for a detailed description.</dd>
  50. </dl>
  51. <h3>Contextual filter validation</h3>
  52. Note: If a view provides a menu option, such as a tab, the tab will not appear if the contextual filter does not validate.
  53. This sytem can have other validators plugged in; by default, Views provides:
  54. <dl>
  55. <dt>Basic validation</dt>
  56. <dd>This validator ensures that the contextual filter is present. A PHP NULL value (from eg. PHP default contextual filter code) will invalidate.</dd>
  57. <dt>Content</dt>
  58. <dd>This validator ensures that the contextual filter is a valid Node ID. You may select which node types the validator will accept.</dd>
  59. <dt>Numeric</dt>
  60. <dd>This validator ensures that the contextual filter is a valid number.</dd>
  61. <dt>PHP Code</dt>
  62. <dd>You may enter arbitrary PHP code here, similar to the "PHP code" option under "Provide default value" in "When the filter value is NOT in the URL" above, to determine if the contextual filter is valid or not.</dd>
  63. <dt>Taxonomy term</dt>
  64. <dd>Ensures that the contextual filter is a valid taxonomy term. This includes options to limit to specific vocabularies and can transform the contextual filter to the right type depending upon the actual contextual filter. Set the contextual filter value type option to the actual type of data that the contextual filter being used is expecting.</dd>
  65. <dt>User</dt>
  66. <dd>Ensures that the contextual filter refers to a valid user. If you select this validator, additional options are available to accept numeric user IDs, usernames or both, as well as to consider a user's role when filtering the view.</dd>
  67. </dl>
  68. If you select the "Specify validation criteria" option to select a specific validator, you will have the option to select an action to take if the filter value does not validate.
  69. <dl>
  70. <dt>Display all results for the specified field</dt>
  71. <dd>Selecting this option will return all values if the filter value does not validate, similar to "Display all results for the specified field" under "When the filter value is not in the URL" above.</dd>
  72. <dt>Hide View</dt>
  73. <dd>Similar to "Hide view" under "When the filter value is NOT in the URL" above, if this option is selected and the selector does not validate, the view will hide itself. If the view is a block, nothing will appear. If it is a page, it will throw a 404 and present a "Page not found" error.</dd>
  74. <dt>Return Summary</dt>
  75. <dd>If you select this option and the filter does not validate, a summary of all values that are valid will be returned, as in the option of the same name under "When the filter value is NOT in the URL above."</dd>
  76. <dt>Display contents of "No results found"</dt>
  77. <dd>If this option is selected and the selector does not validate, the value specified under "No results behavior" on the main view page will be displayed.</dd>
  78. </dl>
  79. <h3>Adminstrative title</h3>
  80. Located under the "More" group at the bottom of the "Contextual filters" menu, this option allows you to specify a custom name for the contextual filter. This may be particularly useful if you use the same contextual filter twice and you'd like to distinguish between the two filters.
  81. <h3>Grouping of contextual filters</h3>
  82. Even though contextual filters do not appear in the "<em>and/or</em>" user interface for sorting and grouping regular filters, contextual filters are always added to the <em>first</em> group of filters. Thus the order of the groups can cause the contextual filter to have entirely different effects on the results of a view that has contextual filters. Even though differences might not be apparent through the user interface.
  83. Multiple contextual filters are therefore always in the same "and/or" group of filters, and can not be placed in different groups. There is <a href="http://drupal.org/node/357082">an effort to add this feature</a>.