1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Definition of views_handler_area_text.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Views area text handler.
|
10
|
*
|
11
|
* @ingroup views_area_handlers
|
12
|
*/
|
13
|
class views_handler_area_text extends views_handler_area {
|
14
|
|
15
|
/**
|
16
|
* {@inheritdoc}
|
17
|
*/
|
18
|
public function option_definition() {
|
19
|
$options = parent::option_definition();
|
20
|
$options['content'] = array(
|
21
|
'default' => '',
|
22
|
'translatable' => TRUE,
|
23
|
'format_key' => 'format',
|
24
|
);
|
25
|
$options['format'] = array(
|
26
|
'default' => NULL,
|
27
|
);
|
28
|
$options['tokenize'] = array(
|
29
|
'default' => FALSE,
|
30
|
'bool' => TRUE,
|
31
|
);
|
32
|
return $options;
|
33
|
}
|
34
|
|
35
|
/**
|
36
|
* {@inheritdoc}
|
37
|
*/
|
38
|
public function options_form(&$form, &$form_state) {
|
39
|
parent::options_form($form, $form_state);
|
40
|
|
41
|
$form['content'] = array(
|
42
|
'#type' => 'text_format',
|
43
|
'#default_value' => $this->options['content'],
|
44
|
'#rows' => 6,
|
45
|
'#format' => isset($this->options['format']) ? $this->options['format'] : filter_default_format(),
|
46
|
'#wysiwyg' => FALSE,
|
47
|
);
|
48
|
|
49
|
// @todo Refactor token handling into a base class.
|
50
|
$form['tokenize'] = array(
|
51
|
'#type' => 'checkbox',
|
52
|
'#title' => t('Use replacement tokens from the first row'),
|
53
|
'#default_value' => $this->options['tokenize'],
|
54
|
);
|
55
|
|
56
|
// Get a list of the available fields and arguments for token replacement.
|
57
|
$options = array();
|
58
|
foreach ($this->view->display_handler->get_handlers('field') as $field => $handler) {
|
59
|
$options[t('Fields')]["[$field]"] = $handler->ui_name();
|
60
|
}
|
61
|
|
62
|
$count = 0;
|
63
|
// This lets us prepare the key as we want it printed.
|
64
|
foreach ($this->view->display_handler->get_handlers('argument') as $arg => $handler) {
|
65
|
$options[t('Arguments')]['%' . ++$count] = t('@argument title', array('@argument' => $handler->ui_name()));
|
66
|
$options[t('Arguments')]['!' . $count] = t('@argument input', array('@argument' => $handler->ui_name()));
|
67
|
}
|
68
|
|
69
|
if (!empty($options)) {
|
70
|
$output = '<p>'
|
71
|
. t("The following tokens are available. If you would like to have the characters '[' and ']' please use the html entity codes '%5B' or '%5D' or they will get replaced with empty space.")
|
72
|
. '</p>';
|
73
|
foreach (array_keys($options) as $type) {
|
74
|
if (!empty($options[$type])) {
|
75
|
$items = array();
|
76
|
foreach ($options[$type] as $key => $value) {
|
77
|
$items[] = $key . ' == ' . check_plain($value);
|
78
|
}
|
79
|
$output .= theme('item_list',
|
80
|
array(
|
81
|
'items' => $items,
|
82
|
'type' => $type,
|
83
|
));
|
84
|
}
|
85
|
}
|
86
|
|
87
|
$form['token_help'] = array(
|
88
|
'#type' => 'fieldset',
|
89
|
'#title' => t('Replacement patterns'),
|
90
|
'#collapsible' => TRUE,
|
91
|
'#collapsed' => TRUE,
|
92
|
'#value' => $output,
|
93
|
'#id' => 'edit-options-token-help',
|
94
|
'#dependency' => array(
|
95
|
'edit-options-tokenize' => array(1),
|
96
|
),
|
97
|
'#prefix' => '<div>',
|
98
|
'#suffix' => '</div>',
|
99
|
);
|
100
|
}
|
101
|
}
|
102
|
|
103
|
/**
|
104
|
* {@inheritdoc}
|
105
|
*/
|
106
|
public function options_submit(&$form, &$form_state) {
|
107
|
$form_state['values']['options']['format'] = $form_state['values']['options']['content']['format'];
|
108
|
$form_state['values']['options']['content'] = $form_state['values']['options']['content']['value'];
|
109
|
parent::options_submit($form, $form_state);
|
110
|
}
|
111
|
|
112
|
/**
|
113
|
* {@inheritdoc}
|
114
|
*/
|
115
|
public function render($empty = FALSE) {
|
116
|
$format = isset($this->options['format']) ? $this->options['format'] : filter_default_format();
|
117
|
if (!$empty || !empty($this->options['empty'])) {
|
118
|
return $this->render_textarea($this->options['content'], $format);
|
119
|
}
|
120
|
return '';
|
121
|
}
|
122
|
|
123
|
/**
|
124
|
* Render a text area, using the proper format.
|
125
|
*/
|
126
|
public function render_textarea($value, $format) {
|
127
|
if ($value) {
|
128
|
if ($this->options['tokenize']) {
|
129
|
$value = $this->view->style_plugin->tokenize_value($value, 0);
|
130
|
}
|
131
|
return check_markup($value, $format, '', FALSE);
|
132
|
}
|
133
|
}
|
134
|
|
135
|
}
|