-
Notifications
You must be signed in to change notification settings - Fork 383
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
Prevent video block from causing AMP validation errors in stories #2255
Conversation
…_list on top of shared attr_lists
@swissspidy I'm not sure how to pull this off. I'm looking at something like this: diff --git a/assets/src/components/with-amp-story-settings.js b/assets/src/components/with-amp-story-settings.js
index 67a0240e..042c53a0 100644
--- a/assets/src/components/with-amp-story-settings.js
+++ b/assets/src/components/with-amp-story-settings.js
@@ -48,6 +48,7 @@ const applyWithSelect = withSelect( ( select, props ) => {
const animationOrderEntry = animatedBlocks.find( ( { id } ) => id === props.clientId );
return {
+ select,
parentBlock: getBlock( getBlockRootClientId( props.clientId ) ),
// Use parent's clientId instead of anchor attribute.
// The attribute will be updated via subscribers.
@@ -125,6 +126,7 @@ export default createHigherOrderComponent(
( BlockEdit ) => {
return enhance( ( props ) => {
const {
+ select,
clientId,
name,
attributes,
@@ -156,6 +158,7 @@ export default createHigherOrderComponent(
}
const isImageBlock = 'core/image' === name;
+ const isVideoBlock = 'core/video' === name;
const isTextBlock = 'amp/amp-story-text' === name;
const needsTextSettings = BLOCKS_WITH_TEXT_SETTINGS.includes( name );
const isMovableBlock = ALLOWED_MOVABLE_BLOCKS.includes( name );
@@ -179,6 +182,14 @@ export default createHigherOrderComponent(
setAttributes( { caption: '' } );
}
+ // If we have a video set from an attachment but there is no poster, use the featured image of the video if available.
+ if ( isVideoBlock && attributes.id && ! attributes.poster ) {
+ const media = select( 'core' ).getMedia( attributes.id );
+ if ( media && media.featuredmedia ) {
+ setAttributes( { poster: media.featuredmedia.src } );
+ }
+ }
+
const minTextHeight = 20;
const minTextWidth = 30; But it seems that a |
Also, I'm at a loss for how to hide the “autoplay” and “plays inline” toggles in the inspector controls. |
Same. There doesn't seem to be any class name that could be used for targeting these elements. Two possible options: a) We can try to find a way to add some class names somewhere to allow for this Related upstream issues: |
Indeed. Looks like that's because the attachment post type does not officially support thumbnails, yet the UI for it is exposed in the admin... 🤷♂ I tried to come up with a workaround and 2a430d4 seems to do the trick. |
Fixes #2109.
autoplay:true
. Note the toggle actually has no effect because the sanitizer will automatically supply theautoplay
attribute since it ismandatory
and thus it gets automatically supplied to ensure AMP validation.controls:false
. This seems relevant since the video is notinteractive
, so the controls can't be manipulated anyway.loop:true
attribute default? The background video loops by default.Hide/remove the "Autoplay" toggle (since it must always beDepends on Allow for core block Inspector Controls to be extended and removed WordPress/gutenberg#6023. See Hide Video block toggles for Autoplay and Plays Inline #2283.autoplay:true
).Hide/remove the "Play inline" toggle (and make sure it defaults toDepends on Allow for core block Inspector Controls to be extended and removed WordPress/gutenberg#6023. See Hide Video block toggles for Autoplay and Plays Inline #2283.playsinline:false
).poster
and then removed it, Gutenberg leaves behind an emptyposter
attribute that technically prevents a validation error from happening; this is because of a loose definition ofposter
on theamp-story >> amp-video
spec where the attribute is merelymandatory
, and it leaves its type undefined; but if this in the future changes to be defined asvalue_url
, then this will become a hard AMP validation error, since the plugin's sanitizer wouldn't be able to automatically supply an emptyposter
attribute to circumvent the validation error.)