Flipped table display format

Created on 9 June 2025, 28 days ago

Problem/Motivation

I often use custom fields display data stored across multiple "columns", but only a single "row" (single value). Think of an Organization type description, an Address field, or a Personal profile description as examples.

The table display format is not optimal for those cases. At the same time, I would like to have vertically aligned labels on the one side, and vertically aligned values on the other.

For regular Drupal fields, for such use cases there is the Views flipped table module, or, for immediate content display, we have the Field group table as a submodule of the Field group module. It would be great if Custom field would also support this form of display out-of-the-box, like the regular table display, or html list.

Another approach would be (though I am not sure this can be implemented), to keep the main custom field label as hidden, while preserving the subfield labels as aligning with the regular field labels of a Drupal field (in Field group for instance). This would be especially useful if Custom field is used in combination with regular Drupal fields in an entity display. (I often use Custom field for grouped fields, for performance reasons, but otherwise try to mimic the display of regular fields.)

I am aware of the custom template option, but I thought this would be a relatively often used display mode that could perhaps be offered / selected without custom templating.

Feature request
Status

Active

Version

3.1

Component

User interface

Created by

🇮🇪Ireland marksmith

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @marksmith
  • 🇺🇸United States apmsooner

    I'll take a look when I get a chance and see whats possible for this. Kinda wonder if an actual 'table' element is even necessary for this. CSS grids can maybe achieve the same thing perhaps. I means it's really just 2 columns of data to render, 1st = label, 2nd = value.

  • 🇺🇸United States apmsooner

    Oh, i guess its actually 1 column for the labels and all other columns would be filled with however many values exist. Something like this might be good for creating a comparison component for example.

  • 🇺🇸United States apmsooner

    @marksmith,

    You can check out the branch in the issue fork if you want to test this out. It produces the html structure of what you're asking for. I'm sure there are additional settings you may be interested in that could be considered but not sure what those are. I don't particularly want to put a ton of default styling on tables as I think the theme should generally handle that. If you prefer a patch, i can open a merge request but it's pretty raw as for now.

  • 🇮🇪Ireland marksmith

    Thank you, @apmsooner. I tested the flipped table formatter. It works, but I receive this error message:

    Warning: Undefined array key "formatter_settings" in Drupal\custom_field\Plugin\Field\FieldFormatter\FlippedTableFormatter->viewElements() (line 70 of modules/contrib/custom_field/src/Plugin/Field/FieldFormatter/FlippedTableFormatter.php).

    It appears that the $setting array doesn't contain a formatter_settings key, so we need to check if it exists first.

    I suggest the following change for lines 67-70 which appears to solve the problem.

    Old code:

            // Set the field label for the first column.
            $field_label = $setting['formatter_settings']['field_label'] ?? NULL;
            $label = !empty($field_label) ? $field_label : $custom_item->getLabel();
            $label_display = $setting['formatter_settings']['label_display'];

    New code:

            // Set the field label for the first column.
            $formatter_settings = $setting['formatter_settings'] ?? [];
            $field_label = $formatter_settings['field_label'] ?? NULL;
            $label = !empty($field_label) ? $field_label : $custom_item->getLabel();
            $label_display = $formatter_settings['label_display'] ?? 'above';
  • Merge request !135Resolve #3529226 "Flipped table display" → (Merged) created by apmsooner
  • 🇺🇸United States apmsooner

    @marksmith,

    Opening an MR. That error should be fixed and now the fields are sortable in the formatter settings. This introduces a major feature enhancement that I opened the ticket for in https://www.drupal.org/project/custom_field/issues/3530203 Make fields sortable in formatter displays Active but if we can kill 2 birds with one stone then all of this can get into next release with the help of your review. Note, all the formatters have this sorting functionality (except the non-applicable template one). Please help review all this in whole with these new change and let me know if there are any more warnings or issues you see. It's working well in my local testing.

    Thanks

  • Pipeline finished with Skipped
    21 days ago
    #523495
    • apmsooner committed 45ecea7a on 3.1.x
      Issue #3529226 by apmsooner, marksmith: Flipped table display format
      
  • 🇺🇸United States apmsooner

    I've retained the classes on the rows but otherwise all the cell stuff is clean and therefore the formatter can rely on whatever theme's css for customization to keep it flexible and not make it any harder to theme out then it should be. I fixed one more variable warning but otherwise tested this out on existing and new fields with the patch and it works as designed with no more errors. I'm considering this good and merging. Any additional asks beyond what it already does can be new feature requests.

Production build 0.71.5 2024