I have this rare case of a site where we have a node with an empty body, but the summary is not empty. When outputting the field on the full content view mode with the default format (i.e. the full body content, not the summary), Drupal does render the field wrappers, but an empty body:
<div class="field field-name-body field-type-text-with-summary field-label-hidden">
<div class="field-items">
<div property="content:encoded" class="field-item even"></div>
</div>
</div>
In my case, this gives us unwanted markup, and given our CSS styling, unwanted style output.
Should the field view function not check for output, before actually rendering the field? In this case that would be: text_field_formatter_view(...)
Comment | File | Size | Author |
---|---|---|---|
#31 | interdiff_22_31.txt | 822 bytes | ameymudras |
#31 | 2309585-31.patch | 2.55 KB | ameymudras |
| |||
#22 | empty_text_formatter_for_empty_fields-2309585-22.patch | 2.55 KB | gease |
#22 | empty_text_formatter_for_empty_fields-2309585-22-test-only.patch | 1.44 KB | gease |
#13 | empty_text_formatter_for_empty_fields-2309585-13.patch | 1.09 KB | Petr Illek |
Comments
Comment #1
Martijn Houtman CreditAttribution: Martijn Houtman commentedPatch against current dev version.
Comment #2
Martijn Houtman CreditAttribution: Martijn Houtman commentedComment #3
dcam CreditAttribution: dcam commented8.x needs to be checked for this issue. I can confirm it in 7.x, but due to a known problem with installing 8.x on Windows I'm currently unable to check in that version.
Comment #4
dcam CreditAttribution: dcam commentedI'm able to check D8 now and the issue does exist there.
Comment #6
kenorb CreditAttribution: kenorb commentedComment #10
techwolf12 CreditAttribution: techwolf12 at Unc Inc commentedStill relevant
Comment #13
Petr IllekHi everyone,
recently we have got this issue in our project.
In the meantime Drupal changed the way how it is rendering the field value. So the original patch was not usable.
I've reworked it by adding a condition to the default TextDefaultFormatter.php in latest Drupal 8.7.x-dev.
Comment #14
kybermanHi @Petr,
thanks a lot for this patch. It definitely makes sense to skip output when there is no value.
Tested and works well. This should be easily merged soon.
Comment #15
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedWe should add a test for this. Should be easy enough to add a new testcase in
\Drupal\Tests\text\Kernel\TextFormatterTest
.Comment #16
milos.kroulik CreditAttribution: milos.kroulik commentedIt seems that generated markup has changed:
Comment #17
milos.kroulik CreditAttribution: milos.kroulik at Morpht commented@Sam152 I'm not sure about that class, because in the
setUp()
method there is only a field of typetext
created. Perhaps I should add a whole new class?Also, I wonder if the Component should be changed to text.module, because it's implemented as part of it.
Comment #18
milos.kroulik CreditAttribution: milos.kroulik commentedIt seems that patch from #13 doesn't work anymore. Output from test is:
I will have to try it agan.
Comment #22
geaseUploading patch with test and test only.
Comment #27
JeroenTLet's see if the patch still applies on Drupal 9.4
Comment #30
smustgrave CreditAttribution: smustgrave at Mobomo commentedThis issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.
Think this issue would benefit from an issue summary update. For clear steps to reproduce.
Reviewing the patch
1. It will need to be updated with D10 theme
2. Is this specific to summary? field (ties into issue summary update)
Comment #31
ameymudras CreditAttribution: ameymudras at Salsa Digital commentedComment #32
smustgrave CreditAttribution: smustgrave at Mobomo commentedStill needs the issue summary updates.