HTML tags showing in Caption

Created on 10 January 2024, 10 months ago
Updated 8 February 2024, 9 months ago

I'm new to the Entity Embed module. Just updated an existing site to D10 and version 8.x-1.5 of Entity Embed. When editing a Media Image, the Caption field allows HTML tags. Prior to the upgrade, the caption with tags renders correctly in CK Editor and when viewing the node. After the upgrade, it shows the HTML in both the editor and front end. Any ideas?

https://imgur.com/a/GjNXOO7

πŸ’¬ Support request
Status

Active

Version

1.5

Component

Miscellaneous

Created by

πŸ‡ΊπŸ‡ΈUnited States codesmith San Francisco

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

Comments & Activities

  • Issue created by @codesmith
  • πŸ‡ΊπŸ‡ΈUnited States codesmith San Francisco

    I got this working by creating a custom Twig filter for html_entity_decode and then adding it to a filter-caption.html.twig template override. Bit clunky though. Looks like Drupal Media can handle HTML in captions just fine.

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

    I had the same problem after moving from Drupal 9.5 to 10.2.

    I can't figure out why this abruptly changed the way it rendered (some Twig 3 change?) but it's happening because the value is passed through escapeValue.

    You could always remove the validate from the element, but of course... that's probably a bad idea.

    function my_module_form_entity_embed_dialog_alter(&$form, FormStateInterface $form_state, $form_id) {
      $storage = $form_state->getStorage();
      // On step three of the modal form remove validation from the caption field.
      if (isset($storage['step']) && $storage['step'] === 'embed') {
        if (isset($storage['entity_element']['data-caption'])) {
          unset($form['attributes']['data-caption']['#element_validate']);
        }
      }
    }
    
Production build 0.71.5 2024