Skip to content
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

Rework how and whether galleries are rendered as carousels #4775

Merged
merged 53 commits into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
7a2ca29
Rework how and whether galleries are rendered as carousels
westonruter May 26, 2020
9fb2644
Merge branch 'develop' into fix/gallery-carousel-defaults
pierlon Jun 30, 2020
d186af5
Remove `loading` attribute from img tag since dimensions are not prov…
pierlon Jun 30, 2020
a078832
Merge branch 'develop' into fix/gallery-carousel-defaults
pierlon Jul 6, 2020
2a7ace2
Fix display of HTML captions in AMP carousel
pierlon Jul 7, 2020
6d055ad
Fix lightbox not showing images
pierlon Jul 7, 2020
0f213bd
Merge branch 'develop' into fix/gallery-carousel-defaults
pierlon Jul 13, 2020
38298f3
Merge branch 'develop' into fix/gallery-carousel-defaults
pierlon Jul 17, 2020
19b45c9
Refactor logic handling gallery embed shortcodes and blocks
pierlon Jul 20, 2020
eba5869
Merge branch 'develop' into fix/gallery-carousel-defaults
pierlon Jul 20, 2020
8e261da
Fix lint errors
pierlon Jul 20, 2020
fd3e9f2
Fix test errors
pierlon Jul 20, 2020
03df2b2
Indicate `$caption_node` is an instance of DOMElement
pierlon Jul 20, 2020
9467dcc
Use constants for tag names
pierlon Jul 21, 2020
b7df289
Merge branch 'develop' of github.com:ampproject/amp-wp into fix/galle…
westonruter Jul 21, 2020
bab1fc9
Prevent gallery_style filter from applying to other shortcodes
westonruter Jul 21, 2020
c097f62
Harden matching the class attribute
westonruter Jul 21, 2020
b64cc1e
Use __FUNCTION__ to refer to the current function
westonruter Jul 21, 2020
a6269b5
Improve means of preventing infinite recursion when calling gallery_s…
westonruter Jul 21, 2020
9336e13
Reuse Tag::FIGCAPTION
westonruter Jul 22, 2020
81a8004
Make insertion of `data` attributes more robust
pierlon Jul 22, 2020
2421fb3
Remove re-importing of element
pierlon Jul 22, 2020
7d9a41d
Use already retrieved attributes
pierlon Jul 22, 2020
0bd44f9
Enforce `DOMElement` type for caption slide
pierlon Jul 22, 2020
0ce7c51
Enforce slide node as being an element same as caption
westonruter Jul 22, 2020
adc609d
Ensure gallery caption is retained
pierlon Jul 22, 2020
0c568e6
Fix failing tests
pierlon Jul 22, 2020
a4becff
Remove deprecated AMP props from blocks that may contain them
pierlon Jul 23, 2020
dc70071
Define deprecated array if not defined already
westonruter Jul 23, 2020
edbd630
Improve jsdoc for static analysis
westonruter Jul 23, 2020
f0e9d77
Fix ampLayout attribute name
westonruter Jul 23, 2020
d5fa797
Reset `deprecatedProps` object when done re-rendering block
pierlon Jul 23, 2020
7b1b765
Fix propType for `ampNoLoading` toggle
pierlon Jul 23, 2020
32f224e
Move `deprecatedProps` into `save` method
pierlon Jul 23, 2020
f7be98b
Escape block property value
pierlon Jul 23, 2020
405359b
Simplify check for deprecated prop
pierlon Jul 23, 2020
b7de0f1
Use for/of loop; move mappedAttributes out of removeDeprecatedAmpProps
westonruter Jul 23, 2020
da088e0
Ensure PHP boolean is stringified as true/false
westonruter Jul 23, 2020
fd4f8b6
Eliminate gratuitous use of wp_json_encode()
westonruter Jul 23, 2020
7d9b3ed
Fix issue with image captions not showing in amp-carousel when render…
pierlon Jul 23, 2020
48343af
Supply missing attribute value for gallery shortcode output
westonruter Jul 24, 2020
bb85a02
Ensure data-amp-carousel=true attribute is present for proper styling…
westonruter Jul 24, 2020
9aa0552
Prevent removal of data attributes in sanitize_raw_embeds and fix boo…
westonruter Jul 24, 2020
4bc1439
Use DOMElement as return type for HasCaption::get_caption_element()
westonruter Jul 24, 2020
6687931
Modify the block attributes during its deprecation
pierlon Jul 24, 2020
b2901f0
Introduce ObsoleteBlockAttributeRemover service
westonruter Jul 24, 2020
e3c7afb
Improve logic for obtaining obsolete attribute pattern
westonruter Jul 24, 2020
48eb9d1
Improve phpdoc for ObsoleteBlockAttributeRemover
westonruter Jul 24, 2020
1fa5923
Harden pattern to match block comment and start tag
westonruter Jul 24, 2020
9745353
Revert block deprecation logic
pierlon Jul 24, 2020
6eb20db
Skip adding data attributes for gallery shortcodes
westonruter Jul 24, 2020
88d5ae9
Add tests for ObsoleteBlockAttributeRemover
westonruter Jul 24, 2020
9d7260f
Fix test failure in WP 4.9
westonruter Jul 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
290 changes: 87 additions & 203 deletions assets/src/block-editor/helpers/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions assets/src/block-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import domReady from '@wordpress/dom-ready';
import { withFeaturedImageNotice } from '../common/components';
import { getMinimumFeaturedImageDimensions } from '../common/helpers';
import { withMediaLibraryNotice, AMPPreview } from './components';
import { addAMPAttributes, addAMPExtraProps, filterBlocksEdit, filterBlocksSave, renderPreviewButton } from './helpers';
import { addAMPAttributes, filterBlocksEdit, filterBlocksSave, renderPreviewButton, removeDeprecatedAmpProps } from './helpers';
import './store';

const {
Expand All @@ -29,9 +29,9 @@ plugins.keys().forEach( ( modulePath ) => {
} );

addFilter( 'blocks.registerBlockType', 'ampEditorBlocks/addAttributes', addAMPAttributes );
addFilter( 'blocks.registerBlockType', 'ampEditorBlocks/deprecateProps', removeDeprecatedAmpProps );
addFilter( 'blocks.getSaveElement', 'ampEditorBlocks/filterSave', filterBlocksSave );
addFilter( 'editor.BlockEdit', 'ampEditorBlocks/filterEdit', filterBlocksEdit, 20 );
addFilter( 'blocks.getSaveContent.extraProps', 'ampEditorBlocks/addExtraAttributes', addAMPExtraProps );
addFilter( 'editor.PostFeaturedImage', 'ampEditorBlocks/withFeaturedImageNotice', withFeaturedImageNotice );
addFilter( 'editor.MediaUpload', 'ampEditorBlocks/withMediaLibraryNotice', ( InitialMediaUpload ) => withMediaLibraryNotice( InitialMediaUpload, getMinimumFeaturedImageDimensions() ) );

Expand Down
24 changes: 24 additions & 0 deletions includes/embeds/class-amp-core-block-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,30 @@ public function unregister_embed() {
* @return string Filtered block content.
*/
public function filter_rendered_block( $block_content, $block ) {

if ( isset( $block['attrs'] ) ) {
$injected_attributes = '';
$prop_attribute_mapping = [
'ampLayout' => 'data-amp-layout',
'ampNoLoading' => 'data-amp-noloading',
'ampLightbox' => 'data-amp-lightbox',
'ampCarousel' => 'data-amp-carousel',
];
foreach ( $prop_attribute_mapping as $prop => $attr ) {
if ( isset( $block['attrs'][ $prop ] ) ) {
$property_value = $block['attrs'][ $prop ];
if ( is_bool( $property_value ) ) {
$property_value = $property_value ? 'true' : 'false';
}

$injected_attributes .= sprintf( ' %s="%s"', $attr, esc_attr( $property_value ) );
}
}
if ( $injected_attributes ) {
$block_content = preg_replace( '/(<\w+)/', '$1' . $injected_attributes, $block_content, 1 );
}
}

if ( ! isset( $block['blockName'] ) ) {
return $block_content;
}
Expand Down
Loading