Problem/Motivation
When using the "AMP Text" field formatter for the body field along with Entity Embed, there are some (<amp-*>) Tags that are being stripped out by Drupal's sanitization.
In https://www.drupal.org/project/amp/issues/3017398 there was some work done to allow the ones found by getComponentJs() and also include those libraries/js files.
I'm not sure why, but the <amp-iframe> is not being detected, so I think we should add that js file if the $element['#markup'] contains an amp-iframe tag.
For our specific case, we need to use the amp-iframe tag to include a custom video/audio player (Kaltura) when embedding Videos and Audios in a Body field, with the Entity Embed module.
Steps to reproduce
In our case we see this issue when using Entity Embed and Embed modules, configuring the embed buttons for video/audio to embed a media entity that uses a custom Media Player (which again, in our case is Kaltura). BUT you can reproduce the same issue in a Drupal 9 site, just adding an amp-iframe using ckeditor in a body field:
- Create a new Node display mode to use with AMP
- For the body field in that display mode, set the field formatter to "AMP Text"
- Go create a new node, and using Full HTML in CKEditor, click on "Source", and add a
<amp-iframe>to the body. Example:
<amp-iframe height="480" layout="responsive" sandbox="allow-scripts" src="https://player.vimeo.com/video/109807793?h=bf23a5092a" style="max-width:720px" width="720"> <amp-img layout="fill" placeholder="" src="/path/to/placeholder_fallback_image.png"></amp-img> </amp-iframe> - Save the node
- Go view the node, appending
?ampparameter to it. - You will see that the iframe got stripped out from the markup and only the amp-img image placeholder is displaying.
Proposed resolution
In the
public static function preRenderAmpText($element) {
method from AmpProcessedText add the amp-iframe javascript to the $amp->getComponentJs() array and let the new methods added in https://www.drupal.org/project/amp/issues/3017398 to attach the library and add the tag to the allowed_tags.
Remaining tasks
Add test for embedding iframes?
Issue fork amp-3294164
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
anairamzapSetting to "Needs Review" since a MR was provided and apparently the tests are failing for other reason.