2

[Drupal 8]

I have a List (text) field that allows multiple values, displayed as a check box list when editing. But when viewing the node, only the checked values are displayed.

How can I display all values, with an indicator which ones are checked/unchecked? Is this possible with theming?

What I found so far:

  • For Boolean fields, I can select something like this under "Output format" (e.g., "✔ / ✖"), but this doesn’t seem to be possible for List (text) fields. I guess the workaround would be to use multiple Boolean fields, but this makes Views Exposed Filters harder to use.

  • For Drupal 7, there is the module Selected and unselected values formatter (via the question How to display all values of List (text) instead of just the selected ones?)

  • I could imagine (but didn’t try) it would be possible to create a View and display it instead of the field, but then quick-editing would no longer work for this field, as far as I know.

2 Answers 2

3

You can easily generate a field formatter to output what you need in drupal 8 (generate field formatter => drupal gpff with drupal console) and get the result into a view.

Getting the field definition will allow you to get all possibles values (selected or not) for your list and display items as check or not considering the current node value.

$defs = \Drupal::service('entity_field.manager')->getFieldDefinitions('{ENTITY_TYPE}', '{BUNDLE}');
$field_definition = $defs['{FIELD_NAME}'];

Your custom formatter will be available in views (and everywhere it is usable, node display etc.).

1
1

'Display Selected and Unselected' module - is one of the possible solutions for Drupal 8.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.