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