6 * Argument handler to filter results by target.
10 * Argument handler to filter results by target.
12 class link_views_handler_argument_target
extends views_handler_argument
{
15 * Provide defaults for the argument when a new one is created.
17 function options(&$options) {
18 parent
::options($options);
22 * Provide a default options form for the argument.
24 function options_form(&$form, &$form_state) {
25 $defaults = $this->default_actions();
27 $form['title'] = array(
28 '#prefix' => '<div class="clear-block">',
29 '#suffix' => '</div>',
30 '#type' => 'textfield',
31 '#title' => t('Title'),
32 '#default_value' => $this->options
['title'],
33 '#description' => t('The title to use when this argument is present; it will override the title of the view and titles from previous arguments. You can use percent substitution here to replace with argument titles. Use "%1" for the first argument, "%2" for the second, etc.'),
36 $form['clear_start'] = array(
37 '#value' => '<div class="clear-block">',
40 $form['defaults_start'] = array(
41 '#value' => '<div class="views-left-50">',
44 $form['default_action'] = array(
46 '#title' => t('Action to take if argument is not present'),
47 '#default_value' => $this->options
['default_action'],
50 $form['defaults_stop'] = array(
54 $form['wildcard'] = array(
55 '#prefix' => '<div class="views-right-50">',
56 // prefix and no suffix means these two items will be grouped together.
57 '#type' => 'textfield',
58 '#title' => t('Wildcard'),
60 '#default_value' => $this->options
['wildcard'],
61 '#description' => t('If this value is received as an argument, the argument will be ignored; i.e, "all values"'),
64 $form['wildcard_substitution'] = array(
65 '#suffix' => '</div>',
66 '#type' => 'textfield',
67 '#title' => t('Wildcard title'),
69 '#default_value' => $this->options
['wildcard_substitution'],
70 '#description' => t('The title to use for the wildcard in substitutions elsewhere.'),
73 $form['clear_stop'] = array(
78 $validate_options = array();
79 foreach ($defaults as
$id => $info) {
80 $options[$id] = $info['title'];
81 if (empty($info['default only'])) {
82 $validate_options[$id] = $info['title'];
84 if (!empty($info['form method'])) {
85 $this->{$info['form method']}($form, $form_state);
89 $form['default_action']['#options'] = $options;
91 $form['validate_type'] = array(
93 '#title' => t('Validator'),
94 '#default_value' => $this->options
['validate_type'],
97 $validate_types = array('none' => t('<Basic validation>'));
98 $plugins = views_fetch_plugin_data('argument validator');
99 foreach ($plugins as
$id => $info) {
101 if (!empty($info['type'])) {
103 if (empty($this->definition
['validate type'])) {
106 foreach ((array) $info['type'] as
$type) {
107 if ($type == $this->definition
['validate type']) {
114 // If we decide this validator is ok, add it to the list.
116 $plugin = views_get_plugin('argument validator', $id);
118 $plugin->init($this->view
, $this, $id);
119 if ($plugin->access()) {
120 $plugin->validate_form($form, $form_state, $id);
121 $validate_types[$id] = $info['title'];
127 asort($validate_types);
128 $form['validate_type']['#options'] = $validate_types;
129 // Show this gadget if *anything* but 'none' is selected
131 $form['validate_fail'] = array(
133 '#title' => t('Action to take if argument does not validate'),
134 '#default_value' => $this->options
['validate_fail'],
135 '#options' => $validate_options,
140 * Set up the query for this argument.
142 * The argument sent may be found at $this->argument.
145 $this->ensure_my_table();
146 // Because attributes are stored serialized, our only option is to also
147 // serialize the data we're searching for and use LIKE to find similar data.
148 $this->query
->add_where(0, $this->table_alias .
'.'.
$this->real_field .
" LIKE '%%%s%'", serialize(array('target' => $this->argument
)));