Skip to content

Commit 22dce3b

Browse files
authored
Issue #9: Add list_text support for formatter.
1 parent 6036029 commit 22dce3b

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

font_awesome_field/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ Installation
1212
- Install this module using the official Backdrop CMS instructions at
1313
https://backdropcms.org/guide/modules
1414

15-
- Add a 'Text (short)' field to your entity and set its field formatter to 'Font
16-
Awesome icon'.
15+
- Add a 'Text (short)' or 'List (text)' field to your entity and set its field
16+
formatter to 'Font Awesome icon'.
1717

1818
- When creating an entity with this field, enter the Font Awesome classes into
1919
the field (e.g. 'fa fa-camera-retro' (v4) or 'fas fa-camera-retro' (v5)).

font_awesome_field/font_awesome_field.module

+10-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function font_awesome_field_field_formatter_info() {
1111
return array(
1212
'font_awesome' => array(
1313
'label' => t('Font Awesome icon'),
14-
'field types' => array('text'),
14+
'field types' => array('text', 'list_text'),
1515
),
1616
);
1717
}
@@ -24,7 +24,15 @@ function font_awesome_field_field_formatter_view($entity_type, $entity, $field,
2424

2525
foreach ($items as $delta => $item) {
2626
$classes = array();
27-
$strings = explode(' ', $item['safe_value']);
27+
switch ($field['type']) {
28+
case 'text':
29+
$value = $item['safe_value'];
30+
break;
31+
case 'list_text':
32+
$value = $item['value'];
33+
break;
34+
}
35+
$strings = explode(' ', $value);
2836

2937
// Convert strings to classes.
3038
foreach ($strings as $string) {

0 commit comments

Comments
 (0)