1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Definition of views_plugin_argument_default_raw.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Default argument plugin to use the raw value from the URL.
|
10
|
*
|
11
|
* @ingroup views_argument_default_plugins
|
12
|
*/
|
13
|
class views_plugin_argument_default_raw extends views_plugin_argument_default {
|
14
|
|
15
|
/**
|
16
|
* {@inheritdoc}
|
17
|
*/
|
18
|
public function option_definition() {
|
19
|
$options = parent::option_definition();
|
20
|
$options['index'] = array('default' => '');
|
21
|
$options['use_alias'] = array('default' => FALSE, 'bool' => TRUE);
|
22
|
|
23
|
return $options;
|
24
|
}
|
25
|
|
26
|
/**
|
27
|
* {@inheritdoc}
|
28
|
*/
|
29
|
public function options_form(&$form, &$form_state) {
|
30
|
parent::options_form($form, $form_state);
|
31
|
// Using range(1, 10) will create an array keyed 0-9, which allows arg() to
|
32
|
// properly function since it is also zero-based.
|
33
|
$form['index'] = array(
|
34
|
'#type' => 'select',
|
35
|
'#title' => t('Path component'),
|
36
|
'#default_value' => $this->options['index'],
|
37
|
'#options' => range(1, 10),
|
38
|
'#description' => t('The numbering starts from 1, e.g. on the page admin/structure/types, the 3rd path component is "types".'),
|
39
|
);
|
40
|
$form['use_alias'] = array(
|
41
|
'#type' => 'checkbox',
|
42
|
'#title' => t('Use path alias'),
|
43
|
'#default_value' => $this->options['use_alias'],
|
44
|
'#description' => t('Use path alias instead of internal path.'),
|
45
|
);
|
46
|
}
|
47
|
|
48
|
/**
|
49
|
* {@inheritdoc}
|
50
|
*/
|
51
|
public function get_argument() {
|
52
|
$path = NULL;
|
53
|
if ($this->options['use_alias']) {
|
54
|
$path = drupal_get_path_alias();
|
55
|
}
|
56
|
if ($arg = arg($this->options['index'], $path)) {
|
57
|
return $arg;
|
58
|
}
|
59
|
}
|
60
|
|
61
|
}
|