Module doesn't tolerate anything between opening and closing tags

Created on 29 January 2024, 11 months ago
Updated 29 February 2024, 10 months ago

I have just installed and run this module and nothing happened. Just trying to work out if there are certain criteria that would stop it from working.

I recently upgraded the site from Drupal 9 to 10.2.2.
Client reported images missing, which is because of drupal-entity values not being processed
Ive installed the module, run cron, it reports all replacements are done, but nothing has been changed in the fields.

Here is my output that is in my ckeditor5 fields

<drupal-entity alt="Great Waves features" title="Great Waves features" data-entity-type="media" data-embed-button="media" data-entity-embed-display="view_mode:media.wysiwyg" data-entity-id="972">&nbsp;</drupal-entity>

The entity embed button had already been removed from the editors, but the text editor's allowed HTML tags still contains

<drupal-entity data-entity-type data-embed-button>

Hoping there is something Im missing. Any ideas would be greatly appreciated, thanks.

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada lindsay.wils

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

Merge Requests

Comments & Activities

  • Issue created by @lindsay.wils
  • πŸ‡³πŸ‡±Netherlands eelkeblok Netherlands πŸ‡³πŸ‡±

    It looks like the regular expresion https://git.drupalcode.org/project/convert_entity_media_embed/-/blob/1.0... won't match your tags because there is an   between the opening and closing tag. Obviously we can't "just" add it, because that would break it for other users. You could consider making the change yourself. That would look something like this:

              $value['value'] = preg_replace_callback(
                '/<drupal-entity(.*)data-entity-type="media"(.*)>&nbsp;<\/drupal-entity>/',
                [static::class, 'getDrupalMediaTag'],
                $originalValue
              );
    

    I am open to suggestions to make the code more flexible in what it will accept. I am a little worried .* between the tags would inadvertently match too much.

  • πŸ‡³πŸ‡±Netherlands eelkeblok Netherlands πŸ‡³πŸ‡±

    Adjusted the issue title.

  • πŸ‡¨πŸ‡¦Canada lindsay.wils

    Thank you for the response and info. Thing is, the nbsp; isnt something I have put in there, it is just the default of all of my source code on multiple different sites too.

    Is it possible to match the nbsp; OR nothing between the tags?

    chatGPT confirmed with me this should work

    $value['value'] = preg_replace_callback(
    '/(?: |)<\/drupal-entity>/',
    [static::class, 'getDrupalMediaTag'],
    $originalValue
    );

    source
    https://chat.openai.com/share/123fc68b-702b-49ac-86dc-4b1b3769d3ea

    Sorry, Im not up to speed on submitting patches. Appreciate any help.

  • πŸ‡³πŸ‡±Netherlands eelkeblok Netherlands πŸ‡³πŸ‡±

    That’s certainly possible. I am curious what the source of that nbsp is, considering that no one has encountered it before. If we understand that, we can better assess whether we can expect other β€œcontentβ€œ between the tags.

  • πŸ‡³πŸ‡±Netherlands eelkeblok Netherlands πŸ‡³πŸ‡±

    A very "90% easy, the rest possible" approach might also be to make the entire regex configurable... Maybe with an accompanying, mandatory, "Trust me, I know what I'm doing" checkbox...

  • πŸ‡¨πŸ‡¦Canada lindsay.wils

    Personally, I ended up having a different workaround for this and no longer needed to run the replace, but a configurable regex sounds like a good idea to allow broader control.

    For my case, Im honestly not sure where the nbsp; came from, it was just using a normal entity embed setup to embed old D8 file entities using an Embed Button.

  • First commit to issue fork.
  • Merge request !8consider nbsp between open close tags β†’ (Merged) created by cbfannin
  • πŸ‡³πŸ‡±Netherlands eelkeblok Netherlands πŸ‡³πŸ‡±

    I like this solution, because it only accepts nothing or a single nbsp. That should not pose any risks.

  • Pipeline finished with Skipped
    10 months ago
    #95654
  • Status changed to Fixed 10 months ago
  • πŸ‡³πŸ‡±Netherlands eelkeblok Netherlands πŸ‡³πŸ‡±
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024