Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:ampproject/amp-wp into fix/edito…
Browse files Browse the repository at this point in the history
…r-amp-settings-panel

* 'develop' of github.com:ampproject/amp-wp:
  Render value as fallback instead of entire parent source object
  Fix logic inversion for sources.length
  Ensure `sources` is non-empty array
  Revert "Ensure error `sources` is never `null`"
  Ensure error `sources` is never `null`
  Ensure `sources` is iterated over only if it is non-empty array
  Fix test to account for gutenberg_render_layout_support_flag() (#6850)
  Support converting YouTube iframes with 100% width to amp-youtube with fixed-height (#6837)
  Update Gutenberg package dependencies
  Update Gutenberg package dependencies
  Allow composer normalize plugin to run
  Normalize Composer file
  Update Composer to use AMP toolbox v0.10.0
  • Loading branch information
westonruter committed Jan 22, 2022
2 parents ee55b7e + a32862f commit b209296
Show file tree
Hide file tree
Showing 15 changed files with 716 additions and 400 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-test-measure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ jobs:
- name: Normalize composer.json
run: |
composer require --no-interaction --dev ergebnis/composer-normalize --ignore-platform-reqs
composer config --no-interaction --no-plugins allow-plugins.ergebnis/composer-normalize true
composer --no-interaction normalize --dry-run
#-----------------------------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import { __, sprintf } from '@wordpress/i18n';
function getKeyedSources( sources ) {
const keyedSources = { theme: [], plugin: [], 'mu-plugin': [], embed: [], core: [], blocks: [] };

if ( ! sources?.length ) {
return keyedSources;
}

for ( const source of sources ) {
if ( source.type && source.type in keyedSources ) {
keyedSources[ source.type ].push( source );
Expand Down Expand Up @@ -86,7 +90,7 @@ export function getErrorSourceTitle( sources = [] ) {
output.push( __( 'Core', 'amp' ) );
}

if ( 0 === output.length && 0 < sources.length ) {
if ( ! output.length && sources?.length ) {
output.push( __( 'Unknown', 'amp' ) );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getErrorSourceTitle } from '../get-error-source-title';

describe( 'getErrorSorceTitle', () => {
it( 'returns an empty string if nothing is passed', () => {
expect( getErrorSourceTitle( null ) ).toBe( '' );
expect( getErrorSourceTitle( [] ) ).toBe( '' );
} );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export function useValidationErrorStateUpdates() {
*/
useEffect( () => {
const newValidationErrors = previousValidationErrors.map( ( validationError ) => {
if ( ! validationError.error.sources ) {
if ( ! validationError.error.sources?.length ) {
return validationError;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export function getSourcesFromScannableUrls( scannableUrls = [], { useAmpUrls =
}

for ( const validationError of validationErrors ) {
if ( ! validationError?.sources?.length ) {
continue;
}

for ( const source of validationError.sources ) {
if ( source.type === 'plugin' ) {
const pluginSlug = getPluginSlugFromFile( source.name );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ describe( 'getSourcesFromScannableUrls', () => {
{ type: 'plugin', name: 'jetpack' },
],
},
{
sources: null,
},
],
},
];
Expand Down
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"ext-json": "*",
"ext-libxml": "*",
"ext-spl": "*",
"ampproject/amp-toolbox": "0.9.3",
"ampproject/amp-toolbox": "0.10.0",
"cweagans/composer-patches": "~1.0",
"fasterimage/fasterimage": "1.5.0",
"sabberworm/php-css-parser": "dev-master#bfdd976"
Expand Down Expand Up @@ -76,6 +76,12 @@
]
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"civicrm/composer-downloads-plugin": true,
"ampproject/php-css-parser-install-plugin": true,
"cweagans/composer-patches": true
},
"platform": {
"php": "5.6.20"
},
Expand Down
18 changes: 9 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions includes/embeds/class-amp-base-embed-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public function get_scripts() {
* Get regex pattern for matching HTML attributes from a given tag name.
*
* @since 1.5.0
* @todo This does not currently work with single-quoted attribute values or non-quoted attributes.
*
* @param string $html HTML source haystack.
* @param string $tag_name Tag name.
Expand Down
33 changes: 30 additions & 3 deletions includes/embeds/class-amp-youtube-embed-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @package AMP
*/

use AmpProject\CssLength;
use AmpProject\Dom\Document;
use AmpProject\Dom\Element;
use AmpProject\Extension;
Expand Down Expand Up @@ -92,15 +93,15 @@ public function __construct( $args = [] ) {
*/
public function register_embed() {
add_filter( 'embed_oembed_html', [ $this, 'filter_embed_oembed_html' ], 10, 2 );
add_filter( 'wp_video_shortcode_override', [ $this, 'video_override' ], 10, 2 );
add_filter( 'wp_video_shortcode_override', [ $this, 'video_override' ], PHP_INT_MAX, 2 );
}

/**
* Unregister embed.
*/
public function unregister_embed() {
remove_filter( 'embed_oembed_html', [ $this, 'filter_embed_oembed_html' ], 10 );
remove_filter( 'wp_video_shortcode_override', [ $this, 'video_override' ], 10 );
remove_filter( 'wp_video_shortcode_override', [ $this, 'video_override' ], PHP_INT_MAX );
}

/**
Expand Down Expand Up @@ -145,6 +146,7 @@ public function render( $html, $url, $video_id ) {
$attributes[ $iframe_prop ] = $props[ $iframe_prop ];
}
}
$attributes = $this->amend_fixed_height_layout( $attributes );

$placeholder = $this->get_placeholder_markup( $url, $video_id, $attributes );

Expand Down Expand Up @@ -209,6 +211,8 @@ private function get_amp_component( Document $dom, Element $node ) {
return false;
}

$attributes = $this->amend_fixed_height_layout( $attributes );

$amp_node = AMP_DOM_Utils::create_node(
$dom,
Extension::YOUTUBE,
Expand All @@ -224,6 +228,24 @@ private function get_amp_component( Document $dom, Element $node ) {
return $amp_node;
}

/**
* Amend attributes with fixed-height layout if there is a 100% width present.
*
* @param array $attributes Attributes.
* @return array Amended attributes.
*/
private function amend_fixed_height_layout( $attributes ) {
if (
isset( $attributes[ Attribute::WIDTH ] )
&&
( '100%' === $attributes[ Attribute::WIDTH ] || CssLength::AUTO === $attributes[ Attribute::WIDTH ] )
) {
$attributes[ Attribute::LAYOUT ] = Layout::FIXED_HEIGHT;
$attributes[ Attribute::WIDTH ] = CssLength::AUTO;
}
return $attributes;
}

/**
* Prepare attributes for amp-youtube component.
*
Expand Down Expand Up @@ -297,7 +319,7 @@ private function get_placeholder_element( Element $amp_component, $video_id, $at
Attribute::OBJECT_FIT => 'cover',
];

if ( $attributes[ Attribute::TITLE ] ) {
if ( ! empty( $attributes[ Attribute::TITLE ] ) ) {
$img_attributes[ Attribute::ALT ] = $attributes[ Attribute::TITLE ];
}

Expand Down Expand Up @@ -493,6 +515,11 @@ public function video_override( $html, $attr ) {
return $html;
}

// Construct a tag so that any width/height attributes will be passed along.
if ( ! $html ) {
$html = AMP_HTML_Utils::build_tag( Tag::IFRAME, $attr );
}

return $this->render( $html, $src, $video_id );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2732,7 +2732,7 @@ public static function render_sources( $sources ) {
<?php elseif ( is_scalar( $value ) ) : ?>
<?php echo esc_html( (string) $value ); ?>
<?php else : ?>
<pre><?php echo esc_html( wp_json_encode( $source, 128 /* JSON_PRETTY_PRINT */ | 64 /* JSON_UNESCAPED_SLASHES */ ) ); ?></pre>
<pre><?php echo esc_html( wp_json_encode( $value, 128 /* JSON_PRETTY_PRINT */ | 64 /* JSON_UNESCAPED_SLASHES */ ) ); ?></pre>
<?php endif; ?>
</td>
</tr>
Expand Down
Loading

0 comments on commit b209296

Please sign in to comment.