Problem/Motivation

"Convert line breaks into HTML" filter is placing the `drupal-media` tag within a paragraph. It should exclude this tag, as it excludes others, such as `script` and `iframe`.

This is an alternative solution to #3097338: If a filter wraps the drupal-media tag in a paragraph, the edit button breaks, where the currently recommended fix is to fix drupalmedia plugin.js to be more flexible about what it encounters inside the widget wrapper.

This was only discovered now because we failed to test media embedding with the "Convert line breaks into HTML" filter enabled. Now more people are using Drupal 8.8 and are trying out the media embed feature, so they are reporting some configurations we didn't test against when building the feature. The "Convert line breaks into HTML" filter isn't really necessary with CKEditor, but the checkbox to enable it doesn't have that fact clearly displayed.

Proposed resolution

Add the `drupal-media` tag to the list of tags to exclude.

Remaining tasks

review, discuss, commit

User interface changes

API changes

Data model changes

Release notes snippet

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

oknate created an issue. See original summary.

oknate’s picture

Title: "Convert line breaks into HTML" filter shouldn't wrap drupal-media tag in paragraph » "Convert line breaks into HTML" filter should exclude drupal-media tag
Status: Active » Needs review
FileSize
897 bytes
1.74 KB
oknate’s picture

The last submitted patch, 2: 3100066-2--FAIL.patch, failed testing. View results

alison’s picture

#2 applies cleanly and is effective at fixing the behavior for me, thanks! -- core 8.8.0

oknate’s picture

Thanks for testing. To clarify, @alisonjo315, you mean it fixed #3097338: If a filter wraps the drupal-media tag in a paragraph, the edit button breaks, is that correct?

alison’s picture

Mmmm I mean that, with this patch (#3100066 > #2), the rendered "embedded media" aren't getting wrapped in <p> anymore. (Does that clarify, or?)

oknate’s picture

Yes, that clarifies. Thanks!

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Media Initiative

Simple test coverage that shows the problem.

Simple solution for the problem.

There's nothing more to ask for :) Great job!

Wim Leers’s picture

The issue summary should explain why this is only discovered now (AFAIK: because most Drupal 8 sites use CKEditor, and hence don't use filter_autop anymore).

The issue summary should also be updated to explain that this is an alternative solution to #3097338: If a filter wraps the drupal-media tag in a paragraph, the edit button breaks.

oknate’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update

Updated the issue summary based on Wim's feedback in #10. Also, we may want to backport this to 8.8, as users are running into the bug described in #3097338: If a filter wraps the drupal-media tag in a paragraph, the edit button breaks that is caused by this.

Wim Leers’s picture

Bugfixes are always backported to the current minor :) They just need to be committed to the next minor first. So don't worry about that! 😊

acbramley’s picture

I was having an issue where the Edit Media button wasn't appearing and in my browser console I was getting Cannot read property 'insertBeforeMe' of null plugin.js:242 @phenaproxima pointed me to here and I confirmed that disabling the filter_autop filter fixed the error and caused the button to start appearing (yay!). It looks like this patch will solve that issue too :)

Wim Leers’s picture

Title: "Convert line breaks into HTML" filter should exclude drupal-media tag » "Convert line breaks into HTML" filter should exclude <drupal-media> tag

Fix title nit.

phenaproxima’s picture

This bug is quite a nuisance, and possibly a straight-up disruption, in Drupal 8.8 and later. It even breaks media embedding in Umami (which uses the autop filter). The fix is non-disruptive, and the value of fixing it greatly (IMHO) outweighs any open questions about where or how this should be dealt with.

So, I strongly believe this should be backported to 8.8.x.

phenaproxima’s picture

Opened a follow-up at @lauriii's request to discuss making this configurable: #3102154: Allow filter_autop to be configured to ignore certain tags.

  • lauriii committed 2c4ace9 on 9.0.x
    Issue #3100066 by oknate, Wim Leers, alisonjo315: "Convert line breaks...

  • lauriii committed b4644e2 on 8.9.x
    Issue #3100066 by oknate, Wim Leers, alisonjo315: "Convert line breaks...
lauriii’s picture

Version: 8.9.x-dev » 8.8.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed 2c4ace9 and pushed to 9.0.x and 8.9.x. Thanks!

Leaving open to consider backporting this to 8.8.x

oknate’s picture

Thank you! +1 for Adding to 8.8.x branch! We're getting questions from users about this in the media slack channel, where it causes the 'Edit Media' button to fail, and it's not immediately obvious why.

oknate’s picture

Assigned: oknate » Unassigned

Unassigning from myself.

alison’s picture

With this patch alone (i.e. without the patch from #3097338), my edit button is broken again, with the JS error we discussed over on #3097338. Just mentioning in case it helps other folks.

(I don't have filter_autop enabled anyway, but for some reason, the fix on #3097338 is effective for my situation -- sadly, I don't have steps to reproduce, etc., and I can't troubleshoot further right now -- really just sharing in case it's helpful for anyone else!)

Wim Leers’s picture

@alisonjo315 Which filters do you have enabled? Can you share the source markup so that we can reproduce it?

alexpott’s picture

+1 for the backport.

alexpott’s picture

Status: Patch (to be ported) » Fixed

@larowlan also thinks this is good for backport so I've cherry-picked this to 8.8.x

  • alexpott committed 6ce6ba6 on 8.8.x authored by lauriii
    Issue #3100066 by oknate, Wim Leers, alisonjo315: "Convert line breaks...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.