- 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';
- 🇺🇸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
-
apmsooner →
committed 45ecea7a on 3.1.x
Issue #3529226 by apmsooner, marksmith: Flipped table display format
-
apmsooner →
committed 45ecea7a on 3.1.x
- 🇺🇸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.