-
Notifications
You must be signed in to change notification settings - Fork 384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix handling of gallery carousels in paragraphs and fix no-JS fallbacks #4009
Conversation
Don't worry about reviewing this until the new year!! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved
Hi @westonruter,
Sorry for the delay. This looks good for both the Gallery block and [gallery]
shortcode.
I should have considered the <amp-carousel>
being wrapped in a <p>
when working on this.
Before: <amp-carousel>
wrapped in <p>
After
* @param DOMElement $element Element. | ||
* @return bool If it is an image. | ||
*/ | ||
private function is_image_element( DOMElement $element ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea to extract this into a helper method.
$slide_node->setAttribute( 'layout', 'fill' ); | ||
$slide_node->setAttribute( 'object-fit', 'cover' ); | ||
} elseif ( isset( $slide_node->firstChild->tagName ) && 'amp-img' === $slide_node->firstChild->tagName ) { | ||
} elseif ( $slide_node->firstChild instanceof DOMElement && $this->is_image_element( $slide_node->firstChild ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea to change this to instanceof DOMElement
Testing Steps
|
Verified in QA |
Summary
I found that when a gallery carousel is displayed inside of a paragraph (that is, an
<amp-carousel>
inside of a<p>
), it completely breaks because the use of<div>
inside of the<amp-carousel>
causes it to break out the<p>
(since block level elements can't appear inside of paragraphs).Given this gallery on a non-AMP page:
Where the underlying
post_content
is:The expected rendered gallery is:
But the actual gallery appears as:
By looking at the DOM tree, the issue of the slide divs breaking out of the
amp-carousel
can be clearly seen:After the fix in this PR, the DOM appears properly nested:
No-JS Fallbacks
Additionally, I also found that when JS is turned off in the browser, the carousel images do not display at all. This is because the gallery embed handler was creating an
amp-img
, when it should have been creating animg
so that the image sanitizer would create the necessaryamp-img
with thenoscript > img
fallback content.Before:
After:
Amends #3659. See #3658.
Checklist