Text format wrapper does not honor description_display

Created on 6 February 2015, almost 10 years ago
Updated 28 March 2024, 9 months ago

Problem/Motivation

If I 'wrap' my element into text_format element, the original description_display has no effect anymore. I think this is because text-format-wrapper.html.twig (and maybe the preprocess function) does not take it into account.

See #314385: Make position of #description configurable via the API β†’

Steps to reproduce

  1. Install Drupal core (e.g. version 10.3.x), standard profile.
  2. Configure the 'body' field on 'basic_page' node type to define "Help text" (aka the description) at /admin/structure/types/manage/page/fields/node.page.body
  3. Use hook_preprocess_form_element() to set $variables['description_display'] = 'before';.
  4. Clear all caches.
  5. Visit node/add/page
  6. Behold that the description is still below the text area, not between the title and the text area as expected

Proposed resolution

Remove broken logic in text-format-wrapper.html.twig that tries to handle the description and forces it to happen at the end. Allow form-element.html.twig itself to handle description (which it already does correctly) when the child elements are being rendered.

Remaining tasks

  1. Decide the scope of the fixes we want (see comment #30)
  2. Decide what test coverage is needed (if any)
  3. Reviews / refinements
  4. RTBC
  5. Commit

User interface changes

Setting #description_display in a render array of #type 'processed_text' and setting description_display as a theme variable for formatted text fields now works.

API changes

None.

Data model changes

None.

Release notes snippet

Using the 'description_display' theme variable on formatted text area form elements now works. Previously, the description was always rendered last, regardless of this setting.

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
FilterΒ  β†’

Last updated about 22 hours ago

No maintainer
Created by

πŸ‡·πŸ‡΄Romania vitalie

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡«πŸ‡·France nicolas bouteille

    +1 it is very hard to be able to display the description between the label and textarea for formatted text fields when description is removed in TextFormat.php processFormat() $keys_not_to_copy
    This new approach seems better

  • πŸ‡¬πŸ‡§United Kingdom steven jones

    Sorry to do this, but I've fixed a warning/notice coming from #13.

    The other approach in #19 is probably better, but I don't have time to progress that solution, sorry!

  • Issues need to target 11.x. Also, I'm pretty sure 11.x requires merge requests. So creating new patches won't get us anywhere.

  • πŸ‡ΊπŸ‡ΈUnited States dww

    Ran into this again on another project. πŸ˜… I agree #19 is better, all it does is remove code! Local testing and it's working fine.

    We probably still want tests, so leaving NW and tagged, but I converted #19 into MR !7218 to move this along.

    Also, this summary needs the real template and to be filled in.

  • Pipeline finished with Success
    9 months ago
    Total: 582s
    #131082
  • πŸ‡ΊπŸ‡ΈUnited States dww

    #20 makes sense. I started removing description and related variables from most of these:

    % find . -name text-format-wrapper.html.twig
    ./core/profiles/demo_umami/themes/umami/templates/classy/content-edit/text-format-wrapper.html.twig
    ./core/modules/filter/templates/text-format-wrapper.html.twig
    ./core/themes/stable9/templates/content-edit/text-format-wrapper.html.twig
    ./core/themes/claro/templates/text-format-wrapper.html.twig
    ./core/themes/starterkit_theme/templates/content-edit/text-format-wrapper.html.twig
    ./core/themes/olivero/templates/text-format-wrapper.html.twig
    

    I ran into comments with @see pointing to πŸ› Fix inconsistencies of TextareaWidget and TextareaWithSummaryWidget form elements Needs work , so adding that as related.

    I'm not sure what scope of a fix is appropriate. Currently, the MR only fixes Claro. I know we never touch stable9.

    We can fix Olivero, starterkit_theme and demo_umami. But I'm worried about losing functionality if we completely remove all these lines:

    -  {% if description %}
    -    {%
    -      set description_classes = [
    -        aria_description ? 'form-item__description',
    -        disabled ? 'is-disabled',
    -      ]
    -    %}
    -    <div{{ description_attributes.addClass(description_classes) }}>{{ description }}</div>
    -  {% endif %}
    

    form-element.html.twig itself doesn't add a separate is-disabled class to the description classes, it adds form-item--disabled to the whole wrapper.

    1. Do we care? Can/should we move this is-disabled class on description_classes to form-element.html.twig?
    2. Can we fix modules/filter/templates/text-format-wrapper.html.twig itself?
    3. Should we be removing all mention of aria_description from these templates, since we're not using that anymore?
    4. While we're at it, the module template and most of the themes have a comment about * - attributes: HTML attributes for the containing element. yet they all do something like this this for the containing element:
      <div class="js-text-format-wrapper text-format-wrapper js-form-item form-item">
      

      In practice, attributes is only used for the description:

        {% if description %}
          <div{{ attributes }}>{{ description }}</div>
        {% endif %}
      

      That seems like a separate bug. Sound familiar? Needs follow-up?

    For now, I pushed separate commits for:

    • Olivero
    • starterkit_theme
    • demo_umami
    • modules/filter/templates/text-format-wrapper.html.twig
    • Removing aria_description from all of them

    We can easily revert anything if needed. Curious to see what the bot thinks of all this. Probably some classy test is going to fail about template file hashes changing. πŸ˜…

  • Pipeline finished with Success
    9 months ago
    Total: 493s
    #131109
  • πŸ‡ΊπŸ‡ΈUnited States dww

    Re: #30.4: Reading more closely, that's a big part of what πŸ› Fix inconsistencies of TextareaWidget and TextareaWithSummaryWidget form elements Needs work proposes to fix. So that doesn't need another issue. Hopefully this helps reviewers understand why we're leaving the templates alone in this regard. Perhaps we should preserve the @see comments pointing to #3016343?

    Meanwhile, gave this a real summary.

  • πŸ‡ΊπŸ‡ΈUnited States dww

    A few more edits to make the summary more accurate

  • πŸ‡ΊπŸ‡ΈUnited States dww

    For tests, we could mostly copy modules/system/tests/src/Kernel/Form/ElementsFieldsetTest.php into ElementsProcessedTextTest.php or something (perhaps broaden it to also include textarea?). It feels a little gross to copy/pasta, but for now we're still at N=2 and haven't necessarily hit the Rule of 3. At least not that I'm seeing trying to grep the core code. πŸ˜…

Production build 0.71.5 2024