6 * Plugin to provide a string context
10 * Plugins are described by creating a $plugin array which will be used
11 * by the system that includes this file.
14 'title' => t('String'),
15 'description' => t('A context that is just a string.'),
16 'context' => 'ctools_context_create_string',
17 'edit form' => 'ctools_context_string_settings_form',
19 'keyword' => 'string',
21 'context name' => 'string',
22 'convert list' => array(
23 'raw' => t('Raw string'),
24 'html_safe' => t('HTML-safe string'),
25 'uppercase_words_html_safe' => t('Uppercase words HTML-safe string'),
27 'convert' => 'ctools_context_string_convert',
28 'placeholder form' => array(
29 '#type' => 'textfield',
30 '#description' => t('Enter the string for this context.'),
35 * It's important to remember that $conf is optional here, because contexts
36 * are not always created from the UI.
38 function ctools_context_create_string($empty, $data = NULL, $conf = FALSE) {
39 // The input is expected to be an object as created by ctools_break_phrase
40 // which contains a group of string.
42 $context = new ctools_context('string');
43 $context->plugin = 'string';
49 if ($data !== FALSE ) {
50 // Support the array storage from the settings form but also handle direct input from arguments.
51 $context->data = is_array($data) ? $data['string'] : $data;
52 $context->title = ($conf) ? check_plain($data['identifier']) : check_plain($data);
58 * Convert a context into a string.
60 function ctools_context_string_convert($context, $type) {
63 return $context->data;
65 return check_plain($context->data);
66 case 'uppercase_words_html_safe':
67 return ucwords(str_replace('-', ' ', check_plain($context->data)));
72 * String settings form.
74 function ctools_context_string_settings_form($form, &$form_state) {
75 $conf = &$form_state['conf'];
77 $form['string'] = array(
78 '#title' => t('Enter the string'),
79 '#type' => 'textfield',
82 '#default_value' => $conf['string'],
88 function ctools_context_string_settings_form_submit($form, &$form_state) {
89 $form_state['conf']['string'] = $form_state['values']['string'];