1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
*
|
6
|
* Plugin to provide a string context
|
7
|
*/
|
8
|
|
9
|
/**
|
10
|
* Plugins are described by creating a $plugin array which will be used
|
11
|
* by the system that includes this file.
|
12
|
*/
|
13
|
$plugin = array(
|
14
|
'title' => t('String'),
|
15
|
'description' => t('A context that is just a string.'),
|
16
|
'context' => 'ctools_context_create_string',
|
17
|
'keyword' => 'string',
|
18
|
'no ui' => FALSE,
|
19
|
'context name' => 'string',
|
20
|
'convert list' => array(
|
21
|
'raw' => t('Raw string'),
|
22
|
'html_safe' => t('HTML-safe string'),
|
23
|
),
|
24
|
'convert' => 'ctools_context_string_convert',
|
25
|
'placeholder form' => array(
|
26
|
'#type' => 'textfield',
|
27
|
'#description' => t('Enter the string for this context.'),
|
28
|
),
|
29
|
);
|
30
|
|
31
|
/**
|
32
|
* It's important to remember that $conf is optional here, because contexts
|
33
|
* are not always created from the UI.
|
34
|
*/
|
35
|
function ctools_context_create_string($empty, $data = NULL, $conf = FALSE) {
|
36
|
// The input is expected to be an object as created by ctools_break_phrase
|
37
|
// which contains a group of string.
|
38
|
|
39
|
$context = new ctools_context('string');
|
40
|
$context->plugin = 'string';
|
41
|
|
42
|
if ($empty) {
|
43
|
return $context;
|
44
|
}
|
45
|
|
46
|
if ($data !== FALSE ) {
|
47
|
$context->data = $data;
|
48
|
$context->title = ($conf) ? check_plain($data['identifier']) : check_plain($data);
|
49
|
return $context;
|
50
|
}
|
51
|
}
|
52
|
|
53
|
/**
|
54
|
* Convert a context into a string.
|
55
|
*/
|
56
|
function ctools_context_string_convert($context, $type) {
|
57
|
switch ($type) {
|
58
|
case 'raw':
|
59
|
return $context->data;
|
60
|
case 'html_safe':
|
61
|
return check_plain($context->data);
|
62
|
}
|
63
|
}
|
64
|
|