Commit | Line | Data |
---|---|---|
7f254ad8 AE |
1 | <?php |
2 | ||
3 | /** | |
4 | * @file | |
5 | * | |
6 | * Plugin to provide an argument handler for a raw string | |
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 | 'path placeholder' => 'ctools_string_path_placeholder', // This is in pagemanager. | |
24 | ); | |
25 | ||
26 | /** | |
27 | * Discover if this argument gives us the term we crave. | |
28 | */ | |
29 | function ctools_string_context($arg = NULL, $conf = NULL, $empty = FALSE) { | |
30 | // If unset it wants a generic, unfilled context. | |
31 | if ($empty) { | |
32 | return ctools_context_create_empty('string'); | |
33 | } | |
34 | ||
35 | $context = ctools_context_create('string', $arg); | |
36 | $context->original_argument = $arg; | |
37 | ||
38 | return $context; | |
39 | } | |
40 | ||
41 | /** | |
42 | * Settings form for the argument | |
43 | */ | |
44 | function ctools_string_settings_form(&$form, &$form_state, $conf) { | |
45 | $form['settings']['use_tail'] = array( | |
46 | '#title' => t('Get all arguments after this one'), | |
47 | '#type' => 'checkbox', | |
48 | '#default_value' => !empty($conf['use_tail']), | |
49 | '#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".'), | |
50 | ); | |
51 | // return $form; | |
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 | } |