1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Plugin to provide an argument handler for a raw string.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Plugins are described by creating a $plugin array which will be used
|
10
|
* by the system that includes this file.
|
11
|
*/
|
12
|
$plugin = array(
|
13
|
'title' => t("String"),
|
14
|
// Keyword to use for %substitution.
|
15
|
'keyword' => 'string',
|
16
|
'description' => t('A string is a minimal context that simply holds a string that can be used for some other purpose.'),
|
17
|
'settings form' => 'ctools_string_settings_form',
|
18
|
'context' => 'ctools_string_context',
|
19
|
'placeholder form' => array(
|
20
|
'#type' => 'textfield',
|
21
|
'#description' => t('Enter a value for this argument'),
|
22
|
),
|
23
|
// This is in pagemanager.
|
24
|
'path placeholder' => 'ctools_string_path_placeholder',
|
25
|
);
|
26
|
|
27
|
/**
|
28
|
* Discover if this argument gives us the term we crave.
|
29
|
*/
|
30
|
function ctools_string_context($arg = NULL, $conf = NULL, $empty = FALSE) {
|
31
|
// If unset it wants a generic, unfilled context.
|
32
|
if ($empty) {
|
33
|
return ctools_context_create_empty('string');
|
34
|
}
|
35
|
|
36
|
$context = ctools_context_create('string', $arg);
|
37
|
$context->original_argument = $arg;
|
38
|
|
39
|
return $context;
|
40
|
}
|
41
|
|
42
|
/**
|
43
|
* Settings form for the argument.
|
44
|
*/
|
45
|
function ctools_string_settings_form(&$form, &$form_state, $conf) {
|
46
|
$form['settings']['use_tail'] = array(
|
47
|
'#title' => t('Get all arguments after this one'),
|
48
|
'#type' => 'checkbox',
|
49
|
'#default_value' => !empty($conf['use_tail']),
|
50
|
'#description' => t('If checked, this string will include all arguments. For example, if the path is "path/%" and the user visits "path/foo/bar", if this is not checked the string will be "foo". If it is checked the string will be "foo/bar".'),
|
51
|
);
|
52
|
}
|
53
|
|
54
|
/**
|
55
|
* Switch the placeholder based upon user settings.
|
56
|
*/
|
57
|
function ctools_string_path_placeholder($argument) {
|
58
|
if (empty($argument['settings']['use_tail'])) {
|
59
|
return '%pm_arg';
|
60
|
}
|
61
|
else {
|
62
|
return '%pm_arg_tail';
|
63
|
}
|
64
|
}
|