Problem/Motivation

Add a new FieldFormatter plugin to output text fields as a <details> / <summary> group.

Initial use case for Standard profile: in #3002770: Provide authors with tools to manage transcripts and captions/subtitles for local video and audio there is a plan to add a transcript field to some media bundles. A details element is a compact, unintrusive way to present the transcript close to the video. See a demonstration in comment #4.

Aside from that, it's a general purpose formatter to help authors make good use of a standard HTML element. A few other potential uses:

  • Events - a "venue address" field.
  • Commerce products - a "size info" field.
  • User profiles - a "contact details" field.
  • A long-text-with-summary could populate the <summary> using token replacement from the sub-field.
  • Paragraphs - a question-and-answer paragragh type, with two fields for the question and answer. The answer field would use the details/summary formatter, configured to show the question as the <summary> via token replacement. (See comment #10 for a demo.)
  • Long accessible descriptions for complex images. A flowchart accompanied by a rich text alternative in a collapsed details element. Comment #5 elaborates.

Proposed resolution

The FieldFormatter plugin will have some relevant settings:

  1. A checkbox setting controls whether it is should be open or closed initially, i.e. the <details open> attribute.
  2. Text of the <summary> element. will follow this order:
    • Custom text specified by the site-builder.
    • The field label if no custom text specified
    • Others? Maybe leave that possibility open for contrib. Maybe could be follow-up
  3. As a highly desirable bonus, the summary text can support token replacements from the parent entity. Patch #3 included this, and there is a demo in comment #10. Deferred, needs follow-up issue.

Remaining tasks

  • Implement the formatter.
  • Needs follow-up issue to add token support (and tests) for the summary text.
  • Tests.

User interface changes

TODO place screenshots

API changes

None.

Data model changes

Just the necessary addition to config schema for the new formatter settings.

CommentFileSizeAuthor
#45 3062136-44.patch10.59 KBsmustgrave
#45 interdiff-41-44.txt4.36 KBsmustgrave
#42 afterpatch.jpg11.91 KBgaurav-mathur
#42 beforepatch.jpg15.96 KBgaurav-mathur
#41 3062136-41.patch10.61 KBsmustgrave
#41 interdiff-40-41.txt2.6 KBsmustgrave
#40 rerolldiff_27-40.txt1.67 KBayush.khare
#40 3062136-40.patch9.93 KBayush.khare
#32 3062136-32-formatter-settings-UI-screenshot.png27.24 KBandrewmacpherson
#28 interdiff-3062136-26-27.txt2.56 KBandrewmacpherson
#27 3062136-27.patch10.76 KBandrewmacpherson
#26 interdiff-3062136-22-26.txt5.38 KBphenaproxima
#26 3062136-26.patch8.86 KBphenaproxima
#22 interdiff-3062136-20-22.txt900 bytesandrewmacpherson
#22 details-formatter-3062136-22.patch4.96 KBandrewmacpherson
#20 interdiff-3062136-16-20.txt2.29 KBandrewmacpherson
#20 details-formatter-3062136-20.patch4.97 KBandrewmacpherson
#16 details-formatter-3062136-16.patch4.37 KBandrewmacpherson
#16 interdiff-3062136-12-16.txt4.21 KBandrewmacpherson
#12 interdiff-3062136-3-12.txt4.06 KBandrewmacpherson
#12 details-formatter-3062136-12.patch4.59 KBandrewmacpherson
#10 FAQ-paragraph-manage-display-3062136-10.png50.8 KBandrewmacpherson
#10 FAQ-paragraph-manage-fields-3062136-10.png25.5 KBandrewmacpherson
#10 FAQ-paragraph-rendered-3062136-10.png27.74 KBandrewmacpherson
#4 audio-media-transcript-details-open-3062136-4.png73.46 KBandrewmacpherson
#4 audio-media-transcript-details-collapsed-3062136-4.png37.94 KBandrewmacpherson
#4 audio-media-transcript-field-3062136-4.png129.85 KBandrewmacpherson
#4 details-summary-formatter-settings-summary-3062136-4-.png.png21.91 KBandrewmacpherson
#4 details-summary-formatter-settings-3062136-4-.png38.66 KBandrewmacpherson
#3 details-formatter-3062136-3.patch4.85 KBandrewmacpherson

Comments

andrewmacpherson created an issue. See original summary.

andrewmacpherson’s picture

Issue summary: View changes
andrewmacpherson’s picture

StatusFileSize
new4.85 KB

First draft of a patch. The basic settings are working, including token replacement in custom text setting for <summary>.

andrewmacpherson’s picture

A few screenshots using patch #3.

  1. The formatter settings. A checkbox controls whether it is open/closed. A pair of radio buttons lets you choose between using the field label or custom text as the summary, and a textfield for custom text if you want that.
  2. The formatter settings summary message, on the media bundle's manage display page.
  3. A media edit form. This one has an audio file, and a long text field for a transcript.
  4. Example of a media reference attached to a node, using the Bartik theme. The transcript is in a closed details element, and the "transcript" field name is the <summary>.
  5. The same node with the details element open.
andrewmacpherson’s picture

Issue summary: View changes
Issue tags: +Needs followup

I thought up a new use-case. I knew they'd start flowing soon enough.

RIch text contained in a <details> element could also be used to provide long descriptions of complex images. Flow charts, maps, and the like. The image media entity bundle could have a rich text field, and the rendered media entity would be an image with a collapsed details just afterwards.

With a small bit of hook_preprocess_FOO(), a themer could set up a longdesc or aria-details relationship. That could be a good recipe for the drupal.org handbook page.

Or, we could set up the image media bundle in Standard profile up that way. When editors can embed media using a choice of display modes, an entity view display with a long description will be feasible thing to provide for all Drupal sites,

This idea needs a spin-off issue :-)

Status: Needs review » Needs work

The last submitted patch, 3: details-formatter-3062136-3.patch, failed testing. View results

phenaproxima’s picture

Category: Task » Feature request
Priority: Normal » Major
Issue tags: +Accessibility

@andrewmacpherson demoed this to the UX team this past Tuesday, June 18th, and it went over incredibly well. This patch would allow us to fix A-level WCAG violations that we currently ship in the Standard profile's included media types. So, I'm tagging this as accessibility-related and bumping its priority.

phenaproxima’s picture

Issue tags: +Needs tests

Nice work! I like how simple this is. I'm tagging it for tests as well.

  1. +++ b/core/modules/text/config/schema/text.schema.yml
    @@ -96,6 +96,20 @@ field.formatter.settings.text_trimmed:
    +    details_open:
    +      type: boolean
    +      label: 'Open details group by default.'
    

    I think we should rename this parameter to 'open'.

  2. +++ b/core/modules/text/config/schema/text.schema.yml
    @@ -96,6 +96,20 @@ field.formatter.settings.text_trimmed:
    +    summary_source:
    +      type: string
    +      label: 'Summary text type'
    +    summary_custom_text:
    +      type: string
    +      label: 'Custom summary text'
    

    We probably don't need these to be two distinct settings. Maybe we could just default summary_custom_text to the field label, and let site builders change it if they want.

  3. +++ b/core/modules/text/src/Plugin/Field/FieldFormatter/TextDetailsFormatter.php
    @@ -0,0 +1,136 @@
    +      $summary[] = t('Open by default.');
    

    We should be using $this->t() throughout the class.

  4. +++ b/core/modules/text/src/Plugin/Field/FieldFormatter/TextDetailsFormatter.php
    @@ -0,0 +1,136 @@
    +        $summary[] = XSS::filterAdmin(t('Summary text: ' . $this->getSetting('summary_custom_text')));
    

    Nit: Should be 'Xss::filterAdmin'.

  5. +++ b/core/modules/text/src/Plugin/Field/FieldFormatter/TextDetailsFormatter.php
    @@ -0,0 +1,136 @@
    +          $token_service = \Drupal::token();
    +          $entity = $items->getEntity();
    +          $summary = $token_service->replace(
    +            $this->getSetting('summary_custom_text'),
    +            [$entity->getEntityTypeId() => $entity],
    +            ['langcode' => $item->getLangcode()],
    +            $bubbleable_metadata
    +          );
    +          break;
    

    I think we might want to do the token stuff in a follow-up issue, because we'll want to add some inline help to the configuration form explaining what tokens are available. Removing the tokens, for now, would make this patch easier to commit (with less test coverage needed).

    If we continue to do it here, then we'll certainly want to inject the token service into this class.

  6. +++ b/core/modules/text/src/Plugin/Field/FieldFormatter/TextDetailsFormatter.php
    @@ -0,0 +1,136 @@
    +        '#open' => $this->getSetting('details_open') ? TRUE : NULL,
    

    This should always be boolean, for example:

    '#open' => (bool) $this->getSetting('details_open');

andrewmacpherson’s picture

Re. #8 - thanks for the review. Most of those points are easy to fix address.

Re. #8.5:

I think we might want to do the token stuff in a follow-up issue, because we'll want to add some inline help to the configuration form explaining what tokens are available. Removing the tokens, for now, would make this patch easier to commit (with less test coverage needed).

The part about test coverage makes sense to me. I agree that we can move token support to a follow-up.

The other part about UI text is a fuzzier problem, because we don't currently have a lot of UI text to describe available tokens. Most configuration fields that accept tokens don't actually tell you that you can use tokens. Views and User module are outliers here.

For example, the "Title" field on blocks accepts tokens, but the field doesn't have a #description (see BlockBase::buildConfigurationForm()). Instead, the token module in contrib adds a description and a token browser dialog (see token_form_block_form_alter()).

I think it's worth improving the UI descriptions for fields that accept tokens, but I don't think that should be a blocker to adding token support to this formatter itself. It would be good to see something like the contrib token browser in core eventually.

andrewmacpherson’s picture

Meanwhile, here's a demo what the token replacement can achieve.

Paragraphs - a question-and-answer paragragh type, with two fields for the question and answer. The answer field would use the details/summary formatter, configured to show the question as the <summary> via token replacement.

I got this working! It was as easy as I expected.

  1. You need patch #3 here, together with the the paragraphs and token contrib modules.
  2. Set up a paragraph bundle called "Question and Answer". It will need two text fields. I used a plain text field for the question, and a formatted long text field for the answer.
    Manage fields settings for the Question and Answer paragragh type.
  3. In the manage-display settings for the paragragh bundle:
    • Set the question field to disabled (i.e. the question field is not rendered).
    • Use the Details/Summary formatter for the answer field. Uncheck the "open details by default" option, and use custom text for the summary. The summary can pull in the question using the following token: [paragraph:field_question:value].

    Manage display settings for the Question and Answer paragraph type. The settings for the details/summary formatter are expanded to show the tokens used for the custom summary text.

  4. Set up a node type which has a paragraphs field, with the question-and-answer paragraph permitted.
  5. Here's a screenshot of the resulting paragraph output, using the Bartik theme. The questions are the clickable summary elements, and opening them reveals the answer.
    Two Question and Answer paragraphs. One is open, the other closed.
andrewmacpherson’s picture

Issue summary: View changes
andrewmacpherson’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new4.59 KB
new4.06 KB

New patch addresses most of the points in #8.

8.1 - Fixed.

8.2:

We probably don't need these to be two distinct settings. Maybe we could just default summary_custom_text to the field label

I tried this but ran into a snag. Removing the summary_source radio options was easy enough. The problem was in providing useful default value for the summary text. FormatterBase::defaultSettings() is a static method, so there isn't any object context to get the field definition out of $this.

I don't know how we can get around this, so I have left the summary_source radio buttons in place for now.

8.3 - Fixed.
8.4 - Fixed.

8.5 - I removed the token replacement for now, noted the need for follow-up in the issue summary. I think tokens will be important for scenarios like the paragraph bundle in #10, and the usefulness of this formatter isn't so great without them.

8.6 - Fixed.

phenaproxima’s picture

Status: Needs review » Needs work

Thanks, @andrewmacpherson!

I tried this but ran into a snag. Removing the summary_source radio options was easy enough. The problem was in providing useful default value for the summary text. FormatterBase::defaultSettings() is a static method, so there isn't any object context to get the field definition out of $this.

I don't know how we can get around this, so I have left the summary_source radio buttons in place for now.

In defaultSettings(), we can just have it be an empty string or NULL, I think. Then, in the non-static settingsForm() method, we should have access to $this->fieldDefinition->getLabel(), which would be a good default value.

I'm kicking this back for tests, but this is getting close to ready, IMHO.

andrewmacpherson’s picture

Then, in the non-static settingsForm() method, we should have access to $this->fieldDefinition->getLabel(), which would be a good default value.

Right, I get you. I'll try that.

andrewmacpherson’s picture

Fixed the test failure from #3 and #12. There was a test which expected a specific list of available formatters, and the presence of the new formatter broke that assumption.

Attempted to address #8.2. Removed the summary_source radio buttons. Now there's just a summary_text formatter setting.

Now there's another problem: when you first select the details/summary formatter, there isn't a value saved for the summary_text setting. The field label is pre-filled in the formatter settings form, but it isn't actually stored until you:

  1. Open the formatter settings form,
  2. Press the update button on the formatter settings,
  3. Save the entire manage-display form.

If you don't all of these steps, the stored setting will be empty, and that results in a <details> without a <summary>. Technically, that's allowed in HTML, but the browser fallback isn't very good. I think we should avoid that situation.

Maybe we can check for an empty value in viewElements(), and fill in the field label as a fallback when we render the field. The settingsSummary() is another place where the empty value can be addressed in a similar way. Is this a sane approach though? It feels very hacky pretending there is a stored setting when there isn't.

andrewmacpherson’s picture

Status: Needs work » Needs review
StatusFileSize
new4.21 KB
new4.37 KB

Forgot to upload the patch :-(

phenaproxima’s picture

Maybe we can check for an empty value in viewElements(), and fill in the field label as a fallback when we render the field. The settingsSummary() is another place where the empty value can be addressed in a similar way. Is this a sane approach though? It feels very hacky pretending there is a stored setting when there isn't.

I think that is a perfectly sane approach. We don't have to "pretend" there's a stored value; we simply use the stored value if one exists, or the field label if not. I think that is easy to understand for a developer, and acceptable from a site builder/user perspective (it "just works" even if you don't bother doing any configuring). But if you really don't like it, perhaps we could set the #placeholder text in the settings form, and make it non-required, so that it's clearer that we have a fallback value.

andrewmacpherson’s picture

Wow, that's a rare use of placeholder that is quite useful!

One of the main accessibility/usability objections to the placeholder attribute is that users sometimes don't fill the field in, because they think it already has a value. In this case that would actually be OK, because it's the value that will be used if you don't provide one yourself.

It would be good to use it in combination with a #description which explains that it defaults to the field label. Don't rely on placeholder to provide instructions.

phenaproxima’s picture

It would be good to use it in combination with a #description which explains that it defaults to the field label. Don't rely on placeholder to provide instructions.

Agreed!

andrewmacpherson’s picture

StatusFileSize
new4.97 KB
new2.29 KB

This brings in the ideas discussed in #17-19.

I think this is feature-complete now, except for the token support follow-up. The settings are greatly simplified since #3.

TODO:
Tests. I'll root around in the tests for other formatters to see how they are done.
Update screenshots for issue summary.

andrewmacpherson’s picture

I see that the hook_help() for text module documents the existing formatters, so it might be good to describe the details formatter there too.

andrewmacpherson’s picture

StatusFileSize
new4.96 KB
new900 bytes

Fix silly syntax mistake.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

andrewmacpherson’s picture

Issue tags: +Bug Smash Initiative

Tagging for the bug-smash initiative. When we get this over the line, it will unblock the related plan for audio and video transcripts,, so we can meet TWO level-A success criteria in WCAG and ATAG.

Needs test coverage for the formatter settings and output.

No previous accessibility experience needed!

phenaproxima’s picture

Issue tags: -Needs tests
StatusFileSize
new8.86 KB
new5.38 KB

Wrote a nice kernel test of the formatter settings, and verified that they affect the output as we expect, and did a touch of refactoring to prevent repetition of logic.

andrewmacpherson’s picture

StatusFileSize
new10.76 KB

Thanks! I tried writing a unit test for this a while back, but it kept being fussy about line breaks. I never really understood when to use kernel test, but this one is easy enough to follow, and the test bots say green.

'summary_text' => 'Alas, poor Yorick'
Uber-nitpick: Shakespeare thought highly enough of Yorick to finish that with an exclamation mark :-)

I've updated hook_help() to mention the details formatter.

andrewmacpherson’s picture

StatusFileSize
new2.56 KB

Forgot the interdiff on the last patch

andrewmacpherson’s picture

Issue summary: View changes
andrewmacpherson’s picture

I manually tested the formatter after the little refactoring in #26

gábor hojtsy’s picture

First, this is great, thanks for working on it. I think this is getting really close and is simple and well contained and could be really useful as a transcription field formatter indeed for audio or as a long description field for figures, etc.

+++ b/core/modules/text/src/Plugin/Field/FieldFormatter/TextDetailsFormatter.php
@@ -0,0 +1,121 @@
+ *     "text_with_summary",

I was wondering about this bit. How does this operate with a text field that in itself has a summary part? You have a "Summary" setting on the field settings but then you have a summary on the field value itself too. That is not really handled in the code, and I don't know what would users expect either.

andrewmacpherson’s picture

I realized the screenshots in #10 are out of date. We simplified the formatter settings, so here's a screenshot of what they currently look like using patch #27.

Screenshot of Details/Summary formatter settings. Description follows.

There's a checkbox called "Open details by default", and a textbox called "Summary text".


Re. #31 - Thanks Gábor, that's a good question about the text_with_summary FieldType. I've thought about this too, and there are a few approaches we could take. I don't know if the question should be treated as a blocker here, or suitable for a follow-up.

  1. Don't do anything special with the summary sub-field. After all, the text_default and text_trimmed formatters don't have any special treatment for the summary sub-field when used with a text_with_summary field.
  2. An earlier version of this patch had token support for the formatter settings, but we deferred it to a follow-up. You can access the text_with_summary sub-fields with that, so it's possible to use a token like [node:field_biography:summary]. Comment #10 has a similar demo, but using tokens from a separate field. This has super-power potential, but the downside is that tokens have a significant learning curve. I'd still like to have token support in there eventually.
  3. The issue summary still has a vague note about using other sources for the <summary>. An earlier version of this patch used radio buttons for choosing between the field label, or custom text. My original idea is that Form API #options are an extensible way for modules to add third-party settings. You can see what that looked like in comment #10. We simplified the settings since then, but we could revisit that as a way to offer the text_with_summary summary sub-field as a source? Perhaps settingsForm() method could inspect the field type configuration first.

It's unfortunate that the word "summary" is overloaded here. One use is a HTML element name, the other is a long-established Drupalism. That could make it awkward to find nice UI text for the formatter settings, but we'd think of something.

Common use case: being able to use the summary sub-field for the <summary> means you could use a multi-value text_with_summary field to build a collapsible FAQ, with configuration only! We'd need to fix #2817081: Show 'Edit summary' links on multi-value long text field with summary too though.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

volkswagenchick’s picture

Issue tags: +NorthAmerica2021

Adding NorthAmerica2021 tag for visbility.

DrupalCon NA is April 12-16 with a focus on EOOTB on Wednesday, April 14.
Thanks

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work

D10 version needed
At this time we would need a D10.1.x patch or MR for this issue.

Also if someone could address the follow-up ticket please.

Looks real interesting too!

ayush.khare’s picture

StatusFileSize
new9.93 KB
new1.67 KB

10.1.x Reroll for #27

smustgrave’s picture

Status: Needs work » Needs review
StatusFileSize
new2.6 KB
new10.61 KB

@ayush.khare thank you for the patch unfortunately during the reroll you left out a change for one of the files.

Also The last patch doesn't pass commit checks, could you make sure to run ./core/scripts/dev/commit-code-check.sh before uploading a patch to make sure there are no issues with code formatting. see https://www.drupal.org/docs/develop/development-tools/running-core-devel...

Also removing quickedit as that's removed in D10

gaurav-mathur’s picture

StatusFileSize
new15.96 KB
new11.91 KB

Applied patch #41 successfully works fine.

quietone’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update, +Needs usability review

I started a review by reading the issue summary. First off, I think this is a very useful feature to add. The proposed resolution lists 3 items. The second one is still a point of discussion. If that has been resolved, add it to the Issue Summary. I am adding the tag for an IS update.

This issue has user interface changes and there are no screenshots linked to in the IS. This needs up to date screenshots.

The 'User interface changes' sections says that there are UI changes but there are no up to date screenshots. The section also states that this is using an existing template that is styled for Bartik/Seven. Surely that is out of date. I then searched the issue to see if this has had a usability review. I do not see that so I am adding the tag.

I did not read the comments, instead I then applied the patch and tested it. I added some text fields to the article content type. It appears to work just fine but the text does need to be reviewed. I noticed the following;

  • The changes to the help page do not match the existing style of help text.
  • On 'Manage Display'
    • I noticed that the text 'Open by default.' has a full stop where similar text for other fields does not have a full stop. Also, the text is usually of the form "Category: type", where the new text includes 'Open by default.'
    • The format is 'Details/Summary' which contains a '/' unlike other fields and is not very helpful. Will an admin know what this means?
    • On clicking to get to the settings, I see 'details' used again in the checkbox text 'Open details by default'. I still wonder if an admin will know what this is. It would help if the help text made this clearer.

I skimmed the patch and this jumped out at me.

+++ b/core/modules/text/tests/src/Kernel/TextDetailsFormatterTest.php
@@ -0,0 +1,149 @@
+// cspell:ignore Yorick

Although a nice reference, let's use another test string so we can avoid this.

smustgrave’s picture

Issue summary: View changes
Status: Needs work » Needs review

Updated IS

Before adding screenshots want to make sure we get the language correct.

"Open by default" is no longer a full stop
Changed "Details/Summary" to "Details with Summary tag" - thoughts?
Removed the cspell:ignore Yorick

If language looks good we can add screenshots.

smustgrave’s picture

StatusFileSize
new4.36 KB
new10.59 KB
quietone’s picture

I applied the patch and looked at the help page. Then looked at the patch, making the following points.

  1. +++ b/core/modules/text/text.module
    @@ -32,6 +32,8 @@ function text_help($route_name, RouteMatchInterface $route_match) {
    +      $output .= '<dt>' . t('Displaying the text inside a details group.') . '</dt>';
    

    No period at the end, like the others on the page.

  2. +++ b/core/modules/text/text.module
    @@ -32,6 +32,8 @@ function text_help($route_name, RouteMatchInterface $route_match) {
    +      $output .= '<dd>' . t('Text fields can be displayed in a compact way using the <em>Details with Summary tag</em> format on the <em>Manage display</em> page. The field name will be used for the summary element by default, but this can be customized.') . '</dd>';
    

    This will need work. I don't think we can expect an admin to know what an 'element' is. I suspect that 'but this can be customized' needs to be changed to actual instructions. But this is not for me to decide this is for the UX folks.

I used the new formatter and the supporting text is better, but this needs a Usability review to get all the strings to conform to Drupal standards. That is not something I can do.

Finally, I skimmed the issue summary and see that the remaining tasks is out of date. It states that the formatter needs to be implemented and so do tests. Can that be updated to show the work still to do?

I hope to start a code review tomorrow.

mgifford’s picture

Issue tags: +wcag131

Tagging for WCAG SC 1.3.1

quietone’s picture

Status: Needs review » Needs work

This time I looked at the code in conjunction with testing the patch and running the tests.

  1. +++ b/core/modules/text/src/Plugin/Field/FieldFormatter/TextDetailsFormatter.php
    @@ -0,0 +1,118 @@
    +use Drupal\Component\Utility\Xss;
    

    This should be sorted to ease readability.

  2. +++ b/core/modules/text/src/Plugin/Field/FieldFormatter/TextDetailsFormatter.php
    @@ -0,0 +1,118 @@
    + *   label = @Translation("Details with Summary tag"),
    

    The ux folks will give feedback but this should be sentence case.

  3. +++ b/core/modules/text/src/Plugin/Field/FieldFormatter/TextDetailsFormatter.php
    @@ -0,0 +1,118 @@
    +    if ($this->getSetting('open')) {
    

    Why is this shown only when open? As a user I need to click to find the state. Would it not be better to inform the user of the state?

  4. +++ b/core/modules/text/src/Plugin/Field/FieldFormatter/TextDetailsFormatter.php
    @@ -0,0 +1,118 @@
    +    $bubbleable_metadata->applyTo($elements);
    

    In \Drupal\text\Plugin\Field\FieldFormatter\TextDefaultFormatter::viewElements there is a comment that the ProcessedText elements handles the cache. So, I think this is not necessary.

  5. +++ b/core/modules/text/config/schema/text.schema.yml
    @@ -116,6 +116,17 @@ field.formatter.settings.text_trimmed:
    +      label: 'Open details group by default.'
    

    Labels do not have full stops.

  6. +++ b/core/modules/text/src/Plugin/Field/FieldFormatter/TextDetailsFormatter.php
    @@ -0,0 +1,118 @@
    +      // Compute the text to use for the <summary> element.
    

    Let's make this something helpful. Something along the lines of 'Use the user text for the summary. If not supplied then use the field label." This block is in two methods, so both should be changed.

  7. +++ b/core/modules/text/src/Plugin/Field/FieldFormatter/TextDetailsFormatter.php
    @@ -0,0 +1,118 @@
    +      // Use the field label as a fallback.
    ...
    +        // Use the field label as a fallback.
    

    Can be removed when the comment is changed.

  8. +++ b/core/modules/text/tests/src/Kernel/TextDetailsFormatterTest.php
    @@ -0,0 +1,147 @@
    +use Drupal\field\Entity\FieldConfig;
    

    Sort the use statements.

  9. +++ b/core/modules/text/tests/src/Kernel/TextDetailsFormatterTest.php
    @@ -0,0 +1,147 @@
    + * Tests the text formatters functionality.
    

    As I read this, this tests is testing multiple text formatters. Let's update the comment to reflect that this is testing a specific text formatter.

  10. +++ b/core/modules/text/tests/src/Kernel/TextDetailsFormatterTest.php
    @@ -0,0 +1,147 @@
    +class TextDetailsFormatterTest extends EntityKernelTestBase {
    

    This test has the same setup as TextFormatterTest, does it make sense to extend from that?

  11. +++ b/core/modules/text/tests/src/Kernel/TextDetailsFormatterTest.php
    @@ -0,0 +1,147 @@
    +  /**
    +   * Modules to enable.
    +   *
    +   * @var array
    +   */
    

    This can be inheritdoc.

  12. +++ b/core/modules/text/tests/src/Kernel/TextDetailsFormatterTest.php
    @@ -0,0 +1,147 @@
    +   *   Sets of arguments to pass to the formatter.
    

    Let's be more descriptive. Use an item list to describe the array values.

  13. +++ b/core/modules/text/tests/src/Kernel/TextDetailsFormatterTest.php
    @@ -0,0 +1,147 @@
    +    return [
    

    Why is there no case with 'open' set to TRUE?

  14. +++ b/core/modules/text/text.module
    @@ -32,6 +32,8 @@ function text_help($route_name, RouteMatchInterface $route_match) {
    +      $output .= '<dt>' . t('Displaying the text inside a details group.') . '</dt>';
    

    This is a heading and does not need a full stop.

Finally, I think that this new formatter should be added to the list being tested in \Drupal\Tests\text\Kernel\TextFormatterTest.

I want to take another look at TextDetailsFormatterTest.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

kopeboy’s picture

I would also consider allowing the end user to input the summary text, and even supporting the existing "Text with summary" field type when the summary is required (in this case, check current bug at #3115978: After enabling Require Summary on a field can't save the field).

kopeboy’s picture

We can take inspiration from the details_summary_field_formatter module.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.