-
Notifications
You must be signed in to change notification settings - Fork 0
/
csv_txt_formatter.module
72 lines (63 loc) · 1.78 KB
/
csv_txt_formatter.module
1
2
3
4
5
6
7
8
9
10
11
12
13
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
* @file
* CSV Text Field Formatter module
*/
/**
* Implements hook_field_formatter_info().
*/
function csv_txt_formatter_field_formatter_info() {
return array(
'csv_txt_formatter' => array(
'label' => t('CSV to list'),
'field types' => array('text'),
'settings' => array(
'separator' => ',',
),
),
);
}
/**
* Implements hook_field_formatter_settings_form().
*/
function csv_txt_formatter_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
//This gets the view_mode where our settings are stored
$display = $instance['display'][$view_mode];
//This gets the actual settings
$settings = $display['settings'];
//Initialize the element variable
$element = array();
$element['separator'] = array(
'#type' => 'textfield',
'#title' => t('Separator'),
'#description' => t('Separator, usually comma.'),
'#default_value' => $settings['separator'],
);
return $element;
}
/**
* Implements hook_field_formatter_settings_summary().
*/
function csv_txt_formatter_field_formatter_settings_summary($field, $instance, $view_mode) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$summary = t('Use @separator as csv separator.', array(
'@separator' => $settings['separator'],
));
return $summary;
}
/**
* Implements hook_field_formatter_view().
*/
function csv_txt_formatter_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$settings = $display['settings'];
$element = array();
$csv_text = $items[0]['safe_value'];
$csv_items = explode($settings['separator'], $csv_text);
$element[0] = array(
'#theme' => 'item_list',
'#items' => $csv_items,
'#type' => 'ul',
);
return $element;
}