Newer
Older
* Definition of Drupal\views\Plugin\views\field\FieldPluginBase.
namespace Drupal\views\Plugin\views\field;
Tim Plunkett
committed
use Drupal\views\Plugin\views\HandlerBase;
Daniel Wehner
committed
use Drupal\views\ViewExecutable;
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* @defgroup views_field_handlers Views field handlers
* @{
* Handlers to tell Views how to build and display fields.
*
*/
/**
* Indicator of the render_text() method for rendering a single item.
* (If no render_item() is present).
*/
define('VIEWS_HANDLER_RENDER_TEXT_PHASE_SINGLE_ITEM', 0);
/**
* Indicator of the render_text() method for rendering the whole element.
* (if no render_item() method is available).
*/
define('VIEWS_HANDLER_RENDER_TEXT_PHASE_COMPLETELY', 1);
/**
* Indicator of the render_text() method for rendering the empty text.
*/
define('VIEWS_HANDLER_RENDER_TEXT_PHASE_EMPTY', 2);
/**
* Base field handler that has no options and renders an unformatted field.
*
* Definition terms:
* - additional fields: An array of fields that should be added to the query
* for some purpose. The array is in the form of:
* array('identifier' => array('table' => tablename,
* 'field' => fieldname); as many fields as are necessary
* may be in this array.
* - click sortable: If TRUE, this field may be click sorted.
*
* @ingroup views_field_handlers
*/
Tim Plunkett
committed
abstract class FieldPluginBase extends HandlerBase {
var $field_alias = 'unknown';
var $aliases = array();
Tim Plunkett
committed
/**
* The field value prior to any rewriting.
*
* @var mixed
*/
public $original_value = NULL;
/**
* @var array
* Stores additional fields which get's added to the query.
* The generated aliases are stored in $aliases.
*/
var $additional_fields = array();
/**
Daniel Wehner
committed
* Overrides Drupal\views\Plugin\views\HandlerBase::init().
Daniel Wehner
committed
public function init(ViewExecutable $view, &$options) {
parent::init($view, $options);
$this->additional_fields = array();
if (!empty($this->definition['additional fields'])) {
$this->additional_fields = $this->definition['additional fields'];
}
if (!isset($this->options['exclude'])) {
$this->options['exclude'] = '';
}
}
/**
* Determine if this field can allow advanced rendering.
*
* Fields can set this to FALSE if they do not wish to allow
* token based rewriting or link-making.
*/
function allow_advanced_render() {
return TRUE;
}
/**
* Called to add the field to a query.
*/
public function query() {
$this->ensureMyTable();
// Add the field.
$params = $this->options['group_type'] != 'group' ? array('function' => $this->options['group_type']) : array();
$this->field_alias = $this->query->add_field($this->tableAlias, $this->realField, NULL, $params);
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
$this->add_additional_fields();
}
/**
* Add 'additional' fields to the query.
*
* @param $fields
* An array of fields. The key is an identifier used to later find the
* field alias used. The value is either a string in which case it's
* assumed to be a field on this handler's table; or it's an array in the
* form of
* @code array('table' => $tablename, 'field' => $fieldname) @endcode
*/
function add_additional_fields($fields = NULL) {
if (!isset($fields)) {
// notice check
if (empty($this->additional_fields)) {
return;
}
$fields = $this->additional_fields;
}
$group_params = array();
if ($this->options['group_type'] != 'group') {
$group_params = array(
'function' => $this->options['group_type'],
);
}
if (!empty($fields) && is_array($fields)) {
foreach ($fields as $identifier => $info) {
if (is_array($info)) {
if (isset($info['table'])) {
$table_alias = $this->query->ensure_table($info['table'], $this->relationship);
}
else {
$table_alias = $this->tableAlias;
}
if (empty($table_alias)) {
debug(t('Handler @handler tried to add additional_field @identifier but @table could not be added!', array('@handler' => $this->definition['handler'], '@identifier' => $identifier, '@table' => $info['table'])));
$this->aliases[$identifier] = 'broken';
continue;
}
$params = array();
if (!empty($info['params'])) {
$params = $info['params'];
}
$params += $group_params;
$this->aliases[$identifier] = $this->query->add_field($table_alias, $info['field'], NULL, $params);
}
else {
$this->aliases[$info] = $this->query->add_field($this->tableAlias, $info, NULL, $group_params);
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
}
}
}
}
/**
* Called to determine what to tell the clicksorter.
*/
function click_sort($order) {
if (isset($this->field_alias)) {
// Since fields should always have themselves already added, just
// add a sort on the field.
$params = $this->options['group_type'] != 'group' ? array('function' => $this->options['group_type']) : array();
$this->query->add_orderby(NULL, NULL, $order, $this->field_alias, $params);
}
}
/**
* Determine if this field is click sortable.
*/
function click_sortable() {
return !empty($this->definition['click sortable']);
}
/**
* Get this field's label.
*/
public function label() {
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
if (!isset($this->options['label'])) {
return '';
}
return $this->options['label'];
}
/**
* Return an HTML element based upon the field's element type.
*/
function element_type($none_supported = FALSE, $default_empty = FALSE, $inline = FALSE) {
if ($none_supported) {
if ($this->options['element_type'] === '0') {
return '';
}
}
if ($this->options['element_type']) {
return check_plain($this->options['element_type']);
}
if ($default_empty) {
return '';
}
if ($inline) {
return 'span';
}
if (isset($this->definition['element type'])) {
return $this->definition['element type'];
}
return 'span';
}
/**
* Return an HTML element for the label based upon the field's element type.
*/
function element_label_type($none_supported = FALSE, $default_empty = FALSE) {
if ($none_supported) {
if ($this->options['element_label_type'] === '0') {
return '';
}
}
if ($this->options['element_label_type']) {
return check_plain($this->options['element_label_type']);
}
if ($default_empty) {
return '';
}
return 'span';
}
/**
* Return an HTML element for the wrapper based upon the field's element type.
*/
function element_wrapper_type($none_supported = FALSE, $default_empty = FALSE) {
if ($none_supported) {
if ($this->options['element_wrapper_type'] === '0') {
return 0;
}
}
if ($this->options['element_wrapper_type']) {
return check_plain($this->options['element_wrapper_type']);
}
if ($default_empty) {
return '';
}
return 'div';
}
/**
* Provide a list of elements valid for field HTML.
*
* This function can be overridden by fields that want more or fewer
* elements available, though this seems like it would be an incredibly
* rare occurence.
*/
function get_elements() {
static $elements = NULL;
if (!isset($elements)) {
// @todo Add possible html5 elements.
Daniel Wehner
committed
$elements = array(
'' => t(' - Use default -'),
'0' => t('- None -')
);
$elements += config('views.settings')->get('field_rewrite_elements');
}
return $elements;
}
/**
* Return the class of the field.
*/
function element_classes($row_index = NULL) {
$classes = explode(' ', $this->options['element_class']);
foreach ($classes as &$class) {
$class = $this->tokenize_value($class, $row_index);
Tim Plunkett
committed
$class = drupal_clean_css_identifier($class);
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
}
return implode(' ', $classes);
}
/**
* Replace a value with tokens from the last field.
*
* This function actually figures out which field was last and uses its
* tokens so they will all be available.
*/
function tokenize_value($value, $row_index = NULL) {
if (strpos($value, '[') !== FALSE || strpos($value, '!') !== FALSE || strpos($value, '%') !== FALSE) {
$fake_item = array(
'alter_text' => TRUE,
'text' => $value,
);
// Use isset() because empty() will trigger on 0 and 0 is
// the first row.
if (isset($row_index) && isset($this->view->style_plugin->render_tokens[$row_index])) {
$tokens = $this->view->style_plugin->render_tokens[$row_index];
}
else {
// Get tokens from the last field.
$last_field = end($this->view->field);
if (isset($last_field->last_tokens)) {
$tokens = $last_field->last_tokens;
}
else {
$tokens = $last_field->get_render_tokens($fake_item);
}
}
$value = strip_tags($this->render_altered($fake_item, $tokens));
if (!empty($this->options['alter']['trim_whitespace'])) {
$value = trim($value);
}
}
return $value;
}
/**
* Return the class of the field's label.
*/
function element_label_classes($row_index = NULL) {
$classes = explode(' ', $this->options['element_label_class']);
foreach ($classes as &$class) {
$class = $this->tokenize_value($class, $row_index);
Tim Plunkett
committed
$class = drupal_clean_css_identifier($class);
}
return implode(' ', $classes);
}
/**
* Return the class of the field's wrapper.
*/
function element_wrapper_classes($row_index = NULL) {
$classes = explode(' ', $this->options['element_wrapper_class']);
foreach ($classes as &$class) {
$class = $this->tokenize_value($class, $row_index);
Tim Plunkett
committed
$class = drupal_clean_css_identifier($class);
}
return implode(' ', $classes);
}
Bojan Živanović
committed
/**
* Get the entity matching the current row and relationship.
*
* @param $values
* An object containing all retrieved values.
*/
function get_entity($values) {
$relationship_id = $this->options['relationship'];
if ($relationship_id == 'none') {
return $values->_entity;
}
else {
return $values->_relationship_entities[$relationship_id];
}
}
/**
* Get the value that's supposed to be rendered.
*
* This api exists so that other modules can easy set the values of the field
* without having the need to change the render method as well.
*
* @param $values
* An object containing all retrieved values.
* @param $field
* Optional name of the field where the value is stored.
*/
function get_value($values, $field = NULL) {
$alias = isset($field) ? $this->aliases[$field] : $this->field_alias;
if (isset($values->{$alias})) {
return $values->{$alias};
}
}
/**
* Determines if this field will be available as an option to group the result
* by in the style settings.
*
* @return bool
* TRUE if this field handler is groupable, otherwise FALSE.
*/
function use_string_group_by() {
return TRUE;
}
protected function defineOptions() {
$options = parent::defineOptions();
$options['label'] = array('default' => $this->definition['title'], 'translatable' => TRUE);
$options['exclude'] = array('default' => FALSE, 'bool' => TRUE);
$options['alter'] = array(
'contains' => array(
'alter_text' => array('default' => FALSE, 'bool' => TRUE),
'text' => array('default' => '', 'translatable' => TRUE),
'make_link' => array('default' => FALSE, 'bool' => TRUE),
Daniel Wehner
committed
'path' => array('default' => ''),
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
'absolute' => array('default' => FALSE, 'bool' => TRUE),
'external' => array('default' => FALSE, 'bool' => TRUE),
'replace_spaces' => array('default' => FALSE, 'bool' => TRUE),
'path_case' => array('default' => 'none', 'translatable' => FALSE),
'trim_whitespace' => array('default' => FALSE, 'bool' => TRUE),
'alt' => array('default' => '', 'translatable' => TRUE),
'rel' => array('default' => ''),
'link_class' => array('default' => ''),
'prefix' => array('default' => '', 'translatable' => TRUE),
'suffix' => array('default' => '', 'translatable' => TRUE),
'target' => array('default' => '', 'translatable' => TRUE),
'nl2br' => array('default' => FALSE, 'bool' => TRUE),
'max_length' => array('default' => ''),
'word_boundary' => array('default' => TRUE, 'bool' => TRUE),
'ellipsis' => array('default' => TRUE, 'bool' => TRUE),
'more_link' => array('default' => FALSE, 'bool' => TRUE),
'more_link_text' => array('default' => '', 'translatable' => TRUE),
'more_link_path' => array('default' => ''),
'strip_tags' => array('default' => FALSE, 'bool' => TRUE),
'trim' => array('default' => FALSE, 'bool' => TRUE),
'preserve_tags' => array('default' => ''),
'html' => array('default' => FALSE, 'bool' => TRUE),
),
);
$options['element_type'] = array('default' => '');
$options['element_class'] = array('default' => '');
$options['element_label_type'] = array('default' => '');
$options['element_label_class'] = array('default' => '');
$options['element_label_colon'] = array('default' => TRUE, 'bool' => TRUE);
$options['element_wrapper_type'] = array('default' => '');
$options['element_wrapper_class'] = array('default' => '');
$options['element_default_classes'] = array('default' => TRUE, 'bool' => TRUE);
$options['empty'] = array('default' => '', 'translatable' => TRUE);
$options['hide_empty'] = array('default' => FALSE, 'bool' => TRUE);
$options['empty_zero'] = array('default' => FALSE, 'bool' => TRUE);
$options['hide_alter_empty'] = array('default' => TRUE, 'bool' => TRUE);
return $options;
}
/**
* Performs some cleanup tasks on the options array before saving it.
*/
public function submitOptionsForm(&$form, &$form_state) {
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
$options = &$form_state['values']['options'];
$types = array('element_type', 'element_label_type', 'element_wrapper_type');
$classes = array_combine(array('element_class', 'element_label_class', 'element_wrapper_class'), $types);
foreach ($types as $type) {
if (!$options[$type . '_enable']) {
$options[$type] = '';
}
}
foreach ($classes as $class => $type) {
if (!$options[$class . '_enable'] || !$options[$type . '_enable']) {
$options[$class] = '';
}
}
if (empty($options['custom_label'])) {
$options['label'] = '';
$options['element_label_colon'] = FALSE;
}
}
/**
* Default options form that provides the label widget that all fields
* should have.
*/
public function buildOptionsForm(&$form, &$form_state) {
parent::buildOptionsForm($form, $form_state);
$label = $this->label();
$form['custom_label'] = array(
'#type' => 'checkbox',
'#title' => t('Create a label'),
'#description' => t('Enable to create a label for this field.'),
'#default_value' => $label !== '',
'#weight' => -103,
);
$form['label'] = array(
'#type' => 'textfield',
'#title' => t('Label'),
'#default_value' => $label,
'#states' => array(
'visible' => array(
':input[name="options[custom_label]"]' => array('checked' => TRUE),
),
),
'#weight' => -102,
);
$form['element_label_colon'] = array(
'#type' => 'checkbox',
'#title' => t('Place a colon after the label'),
'#default_value' => $this->options['element_label_colon'],
'#states' => array(
'visible' => array(
':input[name="options[custom_label]"]' => array('checked' => TRUE),
),
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
),
'#weight' => -101,
);
$form['exclude'] = array(
'#type' => 'checkbox',
'#title' => t('Exclude from display'),
'#default_value' => $this->options['exclude'],
'#description' => t('Enable to load this field as hidden. Often used to group fields, or to use as token in another field.'),
'#weight' => -100,
);
$form['style_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Style settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 99,
);
$form['element_type_enable'] = array(
'#type' => 'checkbox',
'#title' => t('Customize field HTML'),
'#default_value' => !empty($this->options['element_type']) || (string) $this->options['element_type'] == '0' || !empty($this->options['element_class']) || (string) $this->options['element_class'] == '0',
'#fieldset' => 'style_settings',
);
$form['element_type'] = array(
'#title' => t('HTML element'),
'#options' => $this->get_elements(),
'#type' => 'select',
'#default_value' => $this->options['element_type'],
'#description' => t('Choose the HTML element to wrap around this field, e.g. H1, H2, etc.'),
'#states' => array(
'visible' => array(
':input[name="options[element_type_enable]"]' => array('checked' => TRUE),
),
),
'#fieldset' => 'style_settings',
);
$form['element_class_enable'] = array(
'#type' => 'checkbox',
'#title' => t('Create a CSS class'),
'#states' => array(
'visible' => array(
':input[name="options[element_type_enable]"]' => array('checked' => TRUE),
),
),
'#default_value' => !empty($this->options['element_class']) || (string) $this->options['element_class'] == '0',
'#fieldset' => 'style_settings',
);
$form['element_class'] = array(
'#title' => t('CSS class'),
'#description' => t('You may use token substitutions from the rewriting section in this class.'),
'#type' => 'textfield',
'#default_value' => $this->options['element_class'],
'#states' => array(
'visible' => array(
':input[name="options[element_type_enable]"]' => array('checked' => TRUE),
':input[name="options[element_class_enable]"]' => array('checked' => TRUE),
),
),
'#fieldset' => 'style_settings',
);
$form['element_label_type_enable'] = array(
'#type' => 'checkbox',
'#title' => t('Customize label HTML'),
'#default_value' => !empty($this->options['element_label_type']) || (string) $this->options['element_label_type'] == '0' || !empty($this->options['element_label_class']) || (string) $this->options['element_label_class'] == '0',
'#fieldset' => 'style_settings',
);
$form['element_label_type'] = array(
'#title' => t('Label HTML element'),
'#options' => $this->get_elements(FALSE),
'#type' => 'select',
'#default_value' => $this->options['element_label_type'],
'#description' => t('Choose the HTML element to wrap around this label, e.g. H1, H2, etc.'),
'#states' => array(
'visible' => array(
':input[name="options[element_label_type_enable]"]' => array('checked' => TRUE),
),
),
'#fieldset' => 'style_settings',
);
$form['element_label_class_enable'] = array(
'#type' => 'checkbox',
'#title' => t('Create a CSS class'),
'#states' => array(
'visible' => array(
':input[name="options[element_label_type_enable]"]' => array('checked' => TRUE),
),
),
'#default_value' => !empty($this->options['element_label_class']) || (string) $this->options['element_label_class'] == '0',
'#fieldset' => 'style_settings',
);
$form['element_label_class'] = array(
'#title' => t('CSS class'),
'#description' => t('You may use token substitutions from the rewriting section in this class.'),
'#type' => 'textfield',
'#default_value' => $this->options['element_label_class'],
'#states' => array(
'visible' => array(
':input[name="options[element_label_type_enable]"]' => array('checked' => TRUE),
':input[name="options[element_label_class_enable]"]' => array('checked' => TRUE),
),
),
'#fieldset' => 'style_settings',
);
$form['element_wrapper_type_enable'] = array(
'#type' => 'checkbox',
'#title' => t('Customize field and label wrapper HTML'),
'#default_value' => !empty($this->options['element_wrapper_type']) || (string) $this->options['element_wrapper_type'] == '0' || !empty($this->options['element_wrapper_class']) || (string) $this->options['element_wrapper_class'] == '0',
'#fieldset' => 'style_settings',
);
$form['element_wrapper_type'] = array(
'#title' => t('Wrapper HTML element'),
'#options' => $this->get_elements(FALSE),
'#type' => 'select',
'#default_value' => $this->options['element_wrapper_type'],
'#description' => t('Choose the HTML element to wrap around this field and label, e.g. H1, H2, etc. This may not be used if the field and label are not rendered together, such as with a table.'),
'#states' => array(
'visible' => array(
':input[name="options[element_wrapper_type_enable]"]' => array('checked' => TRUE),
),
),
'#fieldset' => 'style_settings',
);
$form['element_wrapper_class_enable'] = array(
'#type' => 'checkbox',
'#title' => t('Create a CSS class'),
'#states' => array(
'visible' => array(
':input[name="options[element_wrapper_type_enable]"]' => array('checked' => TRUE),
),
),
'#default_value' => !empty($this->options['element_wrapper_class']) || (string) $this->options['element_wrapper_class'] == '0',
'#fieldset' => 'style_settings',
);
$form['element_wrapper_class'] = array(
'#title' => t('CSS class'),
'#description' => t('You may use token substitutions from the rewriting section in this class.'),
'#type' => 'textfield',
'#default_value' => $this->options['element_wrapper_class'],
'#states' => array(
'visible' => array(
':input[name="options[element_wrapper_class_enable]"]' => array('checked' => TRUE),
':input[name="options[element_wrapper_type_enable]"]' => array('checked' => TRUE),
),
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
),
'#fieldset' => 'style_settings',
);
$form['element_default_classes'] = array(
'#type' => 'checkbox',
'#title' => t('Add default classes'),
'#default_value' => $this->options['element_default_classes'],
'#description' => t('Use default Views classes to identify the field, field label and field content.'),
'#fieldset' => 'style_settings',
);
$form['alter'] = array(
'#title' => t('Rewrite results'),
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 100,
);
if ($this->allow_advanced_render()) {
$form['alter']['#tree'] = TRUE;
$form['alter']['alter_text'] = array(
'#type' => 'checkbox',
'#title' => t('Rewrite the output of this field'),
'#description' => t('Enable to override the output of this field with custom text or replacement tokens.'),
'#default_value' => $this->options['alter']['alter_text'],
);
$form['alter']['text'] = array(
'#title' => t('Text'),
'#type' => 'textarea',
'#default_value' => $this->options['alter']['text'],
'#description' => t('The text to display for this field. You may include HTML. You may enter data from this view as per the "Replacement patterns" below.'),
'#states' => array(
'visible' => array(
':input[name="options[alter][alter_text]"]' => array('checked' => TRUE),
),
),
);
$form['alter']['make_link'] = array(
'#type' => 'checkbox',
'#title' => t('Output this field as a link'),
'#description' => t('If checked, this field will be made into a link. The destination must be given below.'),
'#default_value' => $this->options['alter']['make_link'],
);
$form['alter']['path'] = array(
'#title' => t('Link path'),
'#type' => 'textfield',
'#default_value' => $this->options['alter']['path'],
'#description' => t('The Drupal path or absolute URL for this link. You may enter data from this view as per the "Replacement patterns" below.'),
'#states' => array(
'visible' => array(
':input[name="options[alter][make_link]"]' => array('checked' => TRUE),
),
),
'#maxlength' => 255,
);
$form['alter']['absolute'] = array(
'#type' => 'checkbox',
'#title' => t('Use absolute path'),
'#default_value' => $this->options['alter']['absolute'],
'#states' => array(
'visible' => array(
':input[name="options[alter][make_link]"]' => array('checked' => TRUE),
),
),
);
$form['alter']['replace_spaces'] = array(
'#type' => 'checkbox',
'#title' => t('Replace spaces with dashes'),
'#default_value' => $this->options['alter']['replace_spaces'],
'#states' => array(
'visible' => array(
':input[name="options[alter][make_link]"]' => array('checked' => TRUE),
),
),
);
$form['alter']['external'] = array(
'#type' => 'checkbox',
'#title' => t('External server URL'),
'#default_value' => $this->options['alter']['external'],
'#description' => t("Links to an external server using a full URL: e.g. 'http://www.example.com' or 'www.example.com'."),
'#states' => array(
'visible' => array(
':input[name="options[alter][make_link]"]' => array('checked' => TRUE),
),
),
);
$form['alter']['path_case'] = array(
'#type' => 'select',
'#title' => t('Transform the case'),
'#description' => t('When printing url paths, how to transform the case of the filter value.'),
'#states' => array(
'visible' => array(
':input[name="options[alter][make_link]"]' => array('checked' => TRUE),
),
),
'#options' => array(
'none' => t('No transform'),
'upper' => t('Upper case'),
'lower' => t('Lower case'),
'ucfirst' => t('Capitalize first letter'),
'ucwords' => t('Capitalize each word'),
),
'#default_value' => $this->options['alter']['path_case'],
);
$form['alter']['link_class'] = array(
'#title' => t('Link class'),
'#type' => 'textfield',
'#default_value' => $this->options['alter']['link_class'],
'#description' => t('The CSS class to apply to the link.'),
'#states' => array(
'visible' => array(
':input[name="options[alter][make_link]"]' => array('checked' => TRUE),
),
),
);
$form['alter']['alt'] = array(
'#title' => t('Title text'),
'#type' => 'textfield',
'#default_value' => $this->options['alter']['alt'],
'#description' => t('Text to place as "title" text which most browsers display as a tooltip when hovering over the link.'),
'#states' => array(
'visible' => array(
':input[name="options[alter][make_link]"]' => array('checked' => TRUE),
),
),
);
$form['alter']['rel'] = array(
'#title' => t('Rel Text'),
'#type' => 'textfield',
'#default_value' => $this->options['alter']['rel'],
'#description' => t('Include Rel attribute for use in lightbox2 or other javascript utility.'),
'#states' => array(
'visible' => array(
':input[name="options[alter][make_link]"]' => array('checked' => TRUE),
),
),
);
$form['alter']['prefix'] = array(
'#title' => t('Prefix text'),
'#type' => 'textfield',
'#default_value' => $this->options['alter']['prefix'],
'#description' => t('Any text to display before this link. You may include HTML.'),
'#states' => array(
'visible' => array(
':input[name="options[alter][make_link]"]' => array('checked' => TRUE),
),
),
);
$form['alter']['suffix'] = array(
'#title' => t('Suffix text'),
'#type' => 'textfield',
'#default_value' => $this->options['alter']['suffix'],
'#description' => t('Any text to display after this link. You may include HTML.'),
'#states' => array(
'visible' => array(
':input[name="options[alter][make_link]"]' => array('checked' => TRUE),
),
),
);
$form['alter']['target'] = array(
'#title' => t('Target'),
'#type' => 'textfield',
'#default_value' => $this->options['alter']['target'],
'#description' => t("Target of the link, such as _blank, _parent or an iframe's name. This field is rarely used."),
'#states' => array(
'visible' => array(
':input[name="options[alter][make_link]"]' => array('checked' => TRUE),
),
),
);
// Get a list of the available fields and arguments for token replacement.
$options = array();
Daniel Wehner
committed
foreach ($this->view->display_handler->getHandlers('field') as $field => $handler) {
$options[t('Fields')]["[$field]"] = $handler->adminLabel();
// We only use fields up to (and including) this one.
if ($field == $this->options['id']) {
break;
}
}
$count = 0; // This lets us prepare the key as we want it printed.
Daniel Wehner
committed
foreach ($this->view->display_handler->getHandlers('argument') as $arg => $handler) {
$options[t('Arguments')]['%' . ++$count] = t('@argument title', array('@argument' => $handler->adminLabel()));
$options[t('Arguments')]['!' . $count] = t('@argument input', array('@argument' => $handler->adminLabel()));
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
}
$this->document_self_tokens($options[t('Fields')]);
// Default text.
$output = t('<p>You must add some additional fields to this display before using this field. These fields may be marked as <em>Exclude from display</em> if you prefer. Note that due to rendering order, you cannot use fields that come after this field; if you need a field not listed here, rearrange your fields.</p>');
// We have some options, so make a list.
if (!empty($options)) {
$output = t('<p>The following tokens are available for this field. Note that due to rendering order, you cannot use fields that come after this field; if you need a field not listed here, rearrange your fields.
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.</p>');
foreach (array_keys($options) as $type) {
if (!empty($options[$type])) {
$items = array();
foreach ($options[$type] as $key => $value) {
$items[] = $key . ' == ' . $value;
}
$output .= theme('item_list',
array(
'items' => $items,
'type' => $type
));
}
}
}
// This construct uses 'hidden' and not markup because process doesn't
// run. It also has an extra div because the dependency wants to hide
// the parent in situations like this, so we need a second div to
// make this work.
$form['alter']['help'] = array(
'#type' => 'fieldset',
'#title' => t('Replacement patterns'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#value' => $output,
'#states' => array(
'visible' => array(
array(
':input[name="options[alter][make_link]"]' => array('checked' => TRUE),
),
array(
':input[name="options[alter][alter_text]"]' => array('checked' => TRUE),
),
array(
':input[name="options[alter][more_link]"]' => array('checked' => TRUE),
),
),
),
);
$form['alter']['trim'] = array(
'#type' => 'checkbox',
'#title' => t('Trim this field to a maximum length'),
'#description' => t('Enable to trim the field to a maximum length of characters'),
'#default_value' => $this->options['alter']['trim'],
);
$form['alter']['max_length'] = array(
'#title' => t('Maximum length'),
'#type' => 'textfield',
'#default_value' => $this->options['alter']['max_length'],
'#description' => t('The maximum number of characters this field can be.'),
'#states' => array(
'visible' => array(
':input[name="options[alter][trim]"]' => array('checked' => TRUE),
),
),
);
$form['alter']['word_boundary'] = array(
'#type' => 'checkbox',
'#title' => t('Trim only on a word boundary'),
'#description' => t('If checked, this field be trimmed only on a word boundary. This is guaranteed to be the maximum characters stated or less. If there are no word boundaries this could trim a field to nothing.'),
'#default_value' => $this->options['alter']['word_boundary'],
'#states' => array(
'visible' => array(
':input[name="options[alter][trim]"]' => array('checked' => TRUE),
),
),
);
$form['alter']['ellipsis'] = array(
'#type' => 'checkbox',
'#title' => t('Add an ellipsis'),
'#description' => t('If checked, a "..." will be added if a field was trimmed.'),
'#default_value' => $this->options['alter']['ellipsis'],
'#states' => array(
'visible' => array(
':input[name="options[alter][trim]"]' => array('checked' => TRUE),
),
),
);
$form['alter']['more_link'] = array(
'#type' => 'checkbox',
'#title' => t('Add a read-more link if output is trimmed.'),
'#description' => t('If checked, a read-more link will be added at the end of the trimmed output'),
'#default_value' => $this->options['alter']['more_link'],
'#states' => array(
'visible' => array(
':input[name="options[alter][trim]"]' => array('checked' => TRUE),
),
),
);
$form['alter']['more_link_text'] = array(
'#type' => 'textfield',
'#title' => t('More link text'),
'#default_value' => $this->options['alter']['more_link_text'],
'#description' => t('The text which will be displayed on the more link. You may enter data from this view as per the "Replacement patterns" above.'),
'#states' => array(
'visible' => array(
':input[name="options[alter][trim]"]' => array('checked' => TRUE),
':input[name="options[alter][more_link]"]' => array('checked' => TRUE),
),
),
);
$form['alter']['more_link_path'] = array(
'#type' => 'textfield',
'#title' => t('More link path'),
'#default_value' => $this->options['alter']['more_link_path'],
'#description' => t('The path which is used for the more link. You may enter data from this view as per the "Replacement patterns" above.'),
'#states' => array(
'visible' => array(
':input[name="options[alter][trim]"]' => array('checked' => TRUE),
':input[name="options[alter][more_link]"]' => array('checked' => TRUE),
),
),
);
$form['alter']['html'] = array(
'#type' => 'checkbox',
'#title' => t('Field can contain HTML'),
'#description' => t('If checked, HTML corrector will be run to ensure tags are properly closed after trimming.'),
'#default_value' => $this->options['alter']['html'],
'#states' => array(
'visible' => array(
':input[name="options[alter][trim]"]' => array('checked' => TRUE),
),
),
);
$form['alter']['strip_tags'] = array(
'#type' => 'checkbox',
'#title' => t('Strip HTML tags'),
'#description' => t('If checked, all HTML tags will be stripped.'),