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