Révision 5d12d676
Ajouté par Assos Assos il y a environ 6 ans
drupal7/sites/all/modules/views/includes/base.inc | ||
---|---|---|
2 | 2 |
|
3 | 3 |
/** |
4 | 4 |
* @file |
5 |
* Provides the basic object definitions used by plugins and handlers.
|
|
5 |
* Definition of views_object.
|
|
6 | 6 |
*/ |
7 | 7 |
|
8 | 8 |
/** |
9 |
* Basic definition for many views objects.
|
|
9 |
* Provides the basic object definitions used by plugins and handlers.
|
|
10 | 10 |
*/ |
11 | 11 |
class views_object { |
12 |
|
|
12 | 13 |
/** |
13 | 14 |
* Except for displays, options for the object will be held here. |
14 | 15 |
*/ |
15 |
var $options = array();
|
|
16 |
public $options = array();
|
|
16 | 17 |
|
17 | 18 |
/** |
18 | 19 |
* The top object of a view. |
19 | 20 |
* |
20 | 21 |
* @var view |
21 | 22 |
*/ |
22 |
var $view = NULL;
|
|
23 |
public $view = NULL;
|
|
23 | 24 |
|
24 | 25 |
/** |
25 |
* Handler's definition |
|
26 |
* Handler's definition.
|
|
26 | 27 |
* |
27 | 28 |
* @var array |
28 | 29 |
*/ |
29 |
var $definition;
|
|
30 |
public $definition;
|
|
30 | 31 |
|
31 | 32 |
/** |
32 | 33 |
* Information about options for all kinds of purposes will be held here. |
34 |
* |
|
33 | 35 |
* @code |
34 | 36 |
* 'option_name' => array( |
35 | 37 |
* - 'default' => default value, |
... | ... | |
52 | 54 |
* @see views_object::export_option_always() |
53 | 55 |
* @see views_object::unpack_translatable() |
54 | 56 |
*/ |
55 |
function option_definition() { return array(); } |
|
57 |
public function option_definition() { |
|
58 |
return array(); |
|
59 |
} |
|
60 |
|
|
61 |
/** |
|
62 |
* Collect this handler's option definition and alter them, ready for use. |
|
63 |
* |
|
64 |
* @return array |
|
65 |
* Returns the options of this handler/plugin after allowing for alters. |
|
66 |
* |
|
67 |
* @see hook_views_plugin_option_definition_alter() |
|
68 |
* @see hook_views_handler_option_definition_alter() |
|
69 |
*/ |
|
70 |
function altered_option_definition() { |
|
71 |
$definition = $this->option_definition(); |
|
72 |
if (!empty($this->is_plugin)) { |
|
73 |
// Trigger hook_views_plugin_option_definition_alter(). |
|
74 |
drupal_alter('views_plugin_option_definition', $definition, $this); |
|
75 |
} |
|
76 |
else { |
|
77 |
// Trigger hook_views_handler_option_definition_alter(). |
|
78 |
drupal_alter('views_handler_option_definition', $definition, $this); |
|
79 |
} |
|
80 |
return $definition; |
|
81 |
} |
|
56 | 82 |
|
57 | 83 |
/** |
58 |
* Views handlers use a special construct function so that we can more |
|
59 |
* easily construct them with variable arguments. |
|
84 |
* Views handlers use a special construct function. |
|
85 |
* |
|
86 |
* Allows it to more easily construct them with variable arguments. |
|
60 | 87 |
*/ |
61 |
function construct() { $this->set_default_options(); } |
|
88 |
public function construct() { |
|
89 |
$this->set_default_options(); |
|
90 |
} |
|
62 | 91 |
|
63 | 92 |
/** |
64 |
* Set default options on this object. Called by the constructor in a |
|
65 |
* complex chain to deal with backward compatibility. |
|
93 |
* Set default options on this object. |
|
94 |
* |
|
95 |
* Called by the constructor in a complex chain to deal with backward |
|
96 |
* compatibility. |
|
66 | 97 |
* |
67 | 98 |
* @deprecated since views2 |
68 | 99 |
*/ |
69 |
function options(&$options) { } |
|
100 |
public function options(&$options) { |
|
101 |
} |
|
70 | 102 |
|
71 | 103 |
/** |
72 | 104 |
* Set default options. |
73 |
* For backward compatibility, it sends the options array; this is a |
|
74 |
* feature that will likely disappear at some point. |
|
105 |
* |
|
106 |
* For backward compatibility, it sends the options array; this is a feature |
|
107 |
* that will likely disappear at some point. |
|
75 | 108 |
*/ |
76 |
function set_default_options() { |
|
77 |
$this->_set_option_defaults($this->options, $this->option_definition()); |
|
109 |
public function set_default_options() {
|
|
110 |
$this->_set_option_defaults($this->options, $this->altered_option_definition());
|
|
78 | 111 |
|
79 | 112 |
// Retained for complex defaults plus backward compatibility. |
80 | 113 |
$this->options($this->options); |
81 | 114 |
} |
82 | 115 |
|
83 |
function _set_option_defaults(&$storage, $options, $level = 0) { |
|
116 |
/** |
|
117 |
* |
|
118 |
*/ |
|
119 |
public function _set_option_defaults(&$storage, $options, $level = 0) { |
|
84 | 120 |
foreach ($options as $option => $definition) { |
85 | 121 |
if (isset($definition['contains']) && is_array($definition['contains'])) { |
86 | 122 |
$storage[$option] = array(); |
... | ... | |
96 | 132 |
} |
97 | 133 |
|
98 | 134 |
/** |
99 |
* Unpack options over our existing defaults, drilling down into arrays |
|
100 |
* so that defaults don't get totally blown away.
|
|
135 |
* Unpack options over our existing defaults, drilling down into arrays so
|
|
136 |
* that defaults don't get totally blown away. |
|
101 | 137 |
*/ |
102 |
function unpack_options(&$storage, $options, $definition = NULL, $all = TRUE, $check = TRUE, $localization_keys = array()) { |
|
138 |
public function unpack_options(&$storage, $options, $definition = NULL, $all = TRUE, $check = TRUE, $localization_keys = array()) {
|
|
103 | 139 |
if ($check && !is_array($options)) { |
104 | 140 |
return; |
105 | 141 |
} |
106 | 142 |
|
107 | 143 |
if (!isset($definition)) { |
108 |
$definition = $this->option_definition(); |
|
144 |
$definition = $this->altered_option_definition();
|
|
109 | 145 |
} |
110 | 146 |
|
111 | 147 |
if (!empty($this->view)) { |
112 | 148 |
// Ensure we have a localization plugin. |
113 | 149 |
$this->view->init_localization(); |
114 | 150 |
|
115 |
// Set up default localization keys. Handlers and such set this for us |
|
151 |
// Set up default localization keys. Handlers and such set this for us.
|
|
116 | 152 |
if (empty($localization_keys) && isset($this->localization_keys)) { |
117 | 153 |
$localization_keys = $this->localization_keys; |
118 | 154 |
} |
119 | 155 |
// but plugins don't because there isn't a common init() these days. |
120 |
else if (!empty($this->is_plugin) && empty($localization_keys)) {
|
|
156 |
elseif (!empty($this->is_plugin) && empty($localization_keys)) { |
|
121 | 157 |
if ($this->plugin_type != 'display') { |
122 | 158 |
$localization_keys = array($this->view->current_display); |
123 | 159 |
$localization_keys[] = $this->plugin_type; |
... | ... | |
146 | 182 |
|
147 | 183 |
$this->unpack_options($storage[$key], $value, isset($definition[$key]['contains']) ? $definition[$key]['contains'] : array(), $all, FALSE, array_merge($localization_keys, array($key))); |
148 | 184 |
} |
149 |
// Don't localize strings during editing. When editing, we need to work with
|
|
150 |
// the original data, not the translated version. |
|
151 |
else if (empty($this->view->editing) && !empty($definition[$key]['translatable']) && !empty($value) || !empty($definition['contains'][$key]['translatable']) && !empty($value)) {
|
|
185 |
// Don't localize strings during editing. When editing, we need to work |
|
186 |
// with the original data, not the translated version.
|
|
187 |
elseif (empty($this->view->editing) && !empty($definition[$key]['translatable']) && !empty($value) || !empty($definition['contains'][$key]['translatable']) && !empty($value)) { |
|
152 | 188 |
if (!empty($this->view) && $this->view->is_translatable()) { |
153 | 189 |
// Allow other modules to make changes to the string before it's |
154 | 190 |
// sent for translation. |
... | ... | |
170 | 206 |
$storage[$key] = t($value); |
171 | 207 |
} |
172 | 208 |
} |
173 |
else if ($all || !empty($definition[$key])) {
|
|
209 |
elseif ($all || !empty($definition[$key])) { |
|
174 | 210 |
$storage[$key] = $value; |
175 | 211 |
} |
176 | 212 |
} |
... | ... | |
179 | 215 |
/** |
180 | 216 |
* Let the handler know what its full definition is. |
181 | 217 |
*/ |
182 |
function set_definition($definition) { |
|
218 |
public function set_definition($definition) {
|
|
183 | 219 |
$this->definition = $definition; |
184 | 220 |
if (isset($definition['field'])) { |
185 | 221 |
$this->real_field = $definition['field']; |
186 | 222 |
} |
187 | 223 |
} |
188 | 224 |
|
189 |
function destroy() { |
|
225 |
/** |
|
226 |
* Destructor. |
|
227 |
*/ |
|
228 |
public function destroy() { |
|
190 | 229 |
if (isset($this->view)) { |
191 | 230 |
unset($this->view); |
192 | 231 |
} |
... | ... | |
200 | 239 |
} |
201 | 240 |
} |
202 | 241 |
|
203 |
function export_options($indent, $prefix) { |
|
242 |
/** |
|
243 |
* |
|
244 |
*/ |
|
245 |
public function export_options($indent, $prefix) { |
|
204 | 246 |
$output = ''; |
205 |
foreach ($this->option_definition() as $option => $definition) { |
|
247 |
foreach ($this->altered_option_definition() as $option => $definition) {
|
|
206 | 248 |
$output .= $this->export_option($indent, $prefix, $this->options, $option, $definition, array()); |
207 | 249 |
} |
208 | 250 |
|
209 | 251 |
return $output; |
210 | 252 |
} |
211 | 253 |
|
212 |
function export_option($indent, $prefix, $storage, $option, $definition, $parents) { |
|
254 |
/** |
|
255 |
* |
|
256 |
*/ |
|
257 |
public function export_option($indent, $prefix, $storage, $option, $definition, $parents) { |
|
213 | 258 |
// Do not export options for which we have no settings. |
214 | 259 |
if (!isset($storage[$option])) { |
215 | 260 |
return; |
... | ... | |
220 | 265 |
return; |
221 | 266 |
} |
222 | 267 |
|
223 |
// Special handling for some items |
|
268 |
// Special handling for some items.
|
|
224 | 269 |
if (method_exists($this, $definition['export'])) { |
225 | 270 |
return $this->{$definition['export']}($indent, $prefix, $storage, $option, $definition, $parents); |
226 | 271 |
} |
... | ... | |
262 | 307 |
/** |
263 | 308 |
* Always exports the option, regardless of the default value. |
264 | 309 |
*/ |
265 |
function export_option_always($indent, $prefix, $storage, $option, $definition, $parents) { |
|
310 |
public function export_option_always($indent, $prefix, $storage, $option, $definition, $parents) {
|
|
266 | 311 |
// If there is no default, the option will always be exported. |
267 | 312 |
unset($definition['default']); |
268 | 313 |
// Unset our export method to prevent recursion. |
... | ... | |
273 | 318 |
/** |
274 | 319 |
* Unpacks each handler to store translatable texts. |
275 | 320 |
*/ |
276 |
function unpack_translatables(&$translatable, $parents = array()) { |
|
277 |
foreach ($this->option_definition() as $option => $definition) { |
|
321 |
public function unpack_translatables(&$translatable, $parents = array()) {
|
|
322 |
foreach ($this->altered_option_definition() as $option => $definition) {
|
|
278 | 323 |
$this->unpack_translatable($translatable, $this->options, $option, $definition, $parents, array()); |
279 | 324 |
} |
280 | 325 |
} |
... | ... | |
284 | 329 |
* |
285 | 330 |
* This function run's through all suboptions recursive. |
286 | 331 |
* |
287 |
* @param $translatable |
|
332 |
* @param array $translatable
|
|
288 | 333 |
* Stores all available translatable items. |
289 |
* @param $storage |
|
290 |
* @param $option |
|
291 |
* @param $definition |
|
292 |
* @param $parents |
|
293 |
* @param $keys |
|
334 |
* @param array $storage
|
|
335 |
* @param string $option
|
|
336 |
* @param string $definition
|
|
337 |
* @param array $parents
|
|
338 |
* @param array $keys
|
|
294 | 339 |
*/ |
295 |
function unpack_translatable(&$translatable, $storage, $option, $definition, $parents, $keys = array()) { |
|
340 |
public function unpack_translatable(&$translatable, $storage, $option, $definition, $parents, $keys = array()) {
|
|
296 | 341 |
// Do not export options for which we have no settings. |
297 | 342 |
if (!isset($storage[$option])) { |
298 | 343 |
return; |
299 | 344 |
} |
300 | 345 |
|
301 |
// Special handling for some items |
|
346 |
// Special handling for some items.
|
|
302 | 347 |
if (isset($definition['unpack_translatable']) && method_exists($this, $definition['unpack_translatable'])) { |
303 | 348 |
return $this->{$definition['unpack_translatable']}($translatable, $storage, $option, $definition, $parents, $keys); |
304 | 349 |
} |
... | ... | |
328 | 373 |
if (is_array($value)) { |
329 | 374 |
$this->unpack_translatable($translatable, $options, $key, $definition, $parents, $translation_keys); |
330 | 375 |
} |
331 |
else if (!empty($definition[$key]['translatable']) && !empty($value)) {
|
|
332 |
// Build source data and add to the array |
|
376 |
elseif (!empty($definition[$key]['translatable']) && !empty($value)) { |
|
377 |
// Build source data and add to the array.
|
|
333 | 378 |
$format = NULL; |
334 | 379 |
if (isset($definition['format_key']) && isset($options[$definition['format_key']])) { |
335 | 380 |
$format = $options[$definition['format_key']]; |
... | ... | |
342 | 387 |
} |
343 | 388 |
} |
344 | 389 |
} |
345 |
else if (!empty($definition['translatable']) && !empty($options)) {
|
|
390 |
elseif (!empty($definition['translatable']) && !empty($options)) { |
|
346 | 391 |
$value = $options; |
347 |
// Build source data and add to the array |
|
392 |
// Build source data and add to the array.
|
|
348 | 393 |
$format = NULL; |
349 | 394 |
if (isset($definition['format_key']) && isset($storage[$definition['format_key']])) { |
350 | 395 |
$format = $storage[$definition['format_key']]; |
... | ... | |
356 | 401 |
); |
357 | 402 |
} |
358 | 403 |
} |
404 |
|
|
359 | 405 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules