1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Argument handler to filter results by target.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Argument handler to filter results by target.
|
10 |
|
|
*/
|
11 |
|
|
class link_views_handler_argument_target extends views_handler_argument {
|
12 |
|
|
|
13 |
|
|
/**
|
14 |
|
|
* Provide defaults for the argument when a new one is created.
|
15 |
|
|
*/
|
16 |
|
|
function options(&$options) {
|
17 |
|
|
parent::options($options);
|
18 |
|
|
}
|
19 |
|
|
|
20 |
|
|
/**
|
21 |
|
|
* Provide a default options form for the argument.
|
22 |
|
|
*/
|
23 |
|
|
function options_form(&$form, &$form_state) {
|
24 |
|
|
$defaults = $this->default_actions();
|
25 |
|
|
|
26 |
|
|
$form['title'] = array(
|
27 |
|
|
'#prefix' => '<div class="clear-block">',
|
28 |
|
|
'#suffix' => '</div>',
|
29 |
|
|
'#type' => 'textfield',
|
30 |
|
|
'#title' => t('Title'),
|
31 |
|
|
'#default_value' => $this->options['title'],
|
32 |
|
|
'#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.'),
|
33 |
|
|
);
|
34 |
|
|
|
35 |
|
|
$form['clear_start'] = array(
|
36 |
|
|
'#value' => '<div class="clear-block">',
|
37 |
|
|
);
|
38 |
|
|
|
39 |
|
|
$form['defaults_start'] = array(
|
40 |
|
|
'#value' => '<div class="views-left-50">',
|
41 |
|
|
);
|
42 |
|
|
|
43 |
|
|
$form['default_action'] = array(
|
44 |
|
|
'#type' => 'radios',
|
45 |
|
|
'#title' => t('Action to take if argument is not present'),
|
46 |
|
|
'#default_value' => $this->options['default_action'],
|
47 |
|
|
);
|
48 |
|
|
|
49 |
|
|
$form['defaults_stop'] = array(
|
50 |
|
|
'#value' => '</div>',
|
51 |
|
|
);
|
52 |
|
|
|
53 |
|
|
$form['wildcard'] = array(
|
54 |
|
|
'#prefix' => '<div class="views-right-50">',
|
55 |
|
|
// prefix and no suffix means these two items will be grouped together.
|
56 |
|
|
'#type' => 'textfield',
|
57 |
|
|
'#title' => t('Wildcard'),
|
58 |
|
|
'#size' => 20,
|
59 |
|
|
'#default_value' => $this->options['wildcard'],
|
60 |
|
|
'#description' => t('If this value is received as an argument, the argument will be ignored; i.e, "all values"'),
|
61 |
|
|
);
|
62 |
|
|
|
63 |
|
|
$form['wildcard_substitution'] = array(
|
64 |
|
|
'#suffix' => '</div>',
|
65 |
|
|
'#type' => 'textfield',
|
66 |
|
|
'#title' => t('Wildcard title'),
|
67 |
|
|
'#size' => 20,
|
68 |
|
|
'#default_value' => $this->options['wildcard_substitution'],
|
69 |
|
|
'#description' => t('The title to use for the wildcard in substitutions elsewhere.'),
|
70 |
|
|
);
|
71 |
|
|
|
72 |
|
|
$form['clear_stop'] = array(
|
73 |
|
|
'#value' => '</div>',
|
74 |
|
|
);
|
75 |
|
|
|
76 |
|
|
$options = array();
|
77 |
|
|
$validate_options = array();
|
78 |
|
|
foreach ($defaults as $id => $info) {
|
79 |
|
|
$options[$id] = $info['title'];
|
80 |
|
|
if (empty($info['default only'])) {
|
81 |
|
|
$validate_options[$id] = $info['title'];
|
82 |
|
|
}
|
83 |
|
|
if (!empty($info['form method'])) {
|
84 |
|
|
$this->{$info['form method']}($form, $form_state);
|
85 |
|
|
}
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
$form['default_action']['#options'] = $options;
|
89 |
|
|
|
90 |
|
|
$form['validate_type'] = array(
|
91 |
|
|
'#type' => 'select',
|
92 |
|
|
'#title' => t('Validator'),
|
93 |
|
|
'#default_value' => $this->options['validate_type'],
|
94 |
|
|
);
|
95 |
|
|
|
96 |
|
|
$validate_types = array('none' => t('- Basic validation -'));
|
97 |
|
|
$plugins = views_fetch_plugin_data('argument validator');
|
98 |
|
|
foreach ($plugins as $id => $info) {
|
99 |
|
|
$valid = TRUE;
|
100 |
|
|
if (!empty($info['type'])) {
|
101 |
|
|
$valid = FALSE;
|
102 |
|
|
if (empty($this->definition['validate type'])) {
|
103 |
|
|
continue;
|
104 |
|
|
}
|
105 |
|
|
foreach ((array) $info['type'] as $type) {
|
106 |
|
|
if ($type == $this->definition['validate type']) {
|
107 |
|
|
$valid = TRUE;
|
108 |
|
|
break;
|
109 |
|
|
}
|
110 |
|
|
}
|
111 |
|
|
}
|
112 |
|
|
|
113 |
|
|
// If we decide this validator is ok, add it to the list.
|
114 |
|
|
if ($valid) {
|
115 |
|
|
$plugin = views_get_plugin('argument validator', $id);
|
116 |
|
|
if ($plugin) {
|
117 |
|
|
$plugin->init($this->view, $this, $id);
|
118 |
|
|
if ($plugin->access()) {
|
119 |
|
|
$plugin->validate_form($form, $form_state, $id);
|
120 |
|
|
$validate_types[$id] = $info['title'];
|
121 |
|
|
}
|
122 |
|
|
}
|
123 |
|
|
}
|
124 |
|
|
}
|
125 |
|
|
|
126 |
|
|
asort($validate_types);
|
127 |
|
|
$form['validate_type']['#options'] = $validate_types;
|
128 |
|
|
// Show this gadget if *anything* but 'none' is selected
|
129 |
|
|
|
130 |
|
|
$form['validate_fail'] = array(
|
131 |
|
|
'#type' => 'select',
|
132 |
|
|
'#title' => t('Action to take if argument does not validate'),
|
133 |
|
|
'#default_value' => $this->options['validate_fail'],
|
134 |
|
|
'#options' => $validate_options,
|
135 |
|
|
);
|
136 |
|
|
}
|
137 |
|
|
|
138 |
|
|
/**
|
139 |
|
|
* Set up the query for this argument.
|
140 |
|
|
*
|
141 |
|
|
* The argument sent may be found at $this->argument.
|
142 |
|
|
*/
|
143 |
|
|
function query($group_by = FALSE) {
|
144 |
|
|
$this->ensure_my_table();
|
145 |
|
|
// Because attributes are stored serialized, our only option is to also
|
146 |
|
|
// serialize the data we're searching for and use LIKE to find similar data.
|
147 |
c8740e19
|
Assos Assos
|
$this->query->add_where(0, $this->table_alias . ' . ' . $this->real_field . " LIKE '%%%s%'", serialize(array('target' => $this->argument)));
|
148 |
85ad3d82
|
Assos Assos
|
}
|
149 |
|
|
} |