From e155ad8a81b056ef53a10f881356471228f8cb71 Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Sun, 5 Dec 2021 16:13:16 +0100 Subject: [PATCH 1/3] Move image and gallery blocks to dynamic block registration --- src/wp-includes/blocks/index.php | 4 ++-- tools/webpack/blocks.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/blocks/index.php b/src/wp-includes/blocks/index.php index 727c7f313bf8c..f7382b1e9ae8a 100644 --- a/src/wp-includes/blocks/index.php +++ b/src/wp-includes/blocks/index.php @@ -11,6 +11,8 @@ require ABSPATH . WPINC . '/blocks/calendar.php'; require ABSPATH . WPINC . '/blocks/categories.php'; require ABSPATH . WPINC . '/blocks/file.php'; +require ABSPATH . WPINC . '/blocks/gallery.php'; +require ABSPATH . WPINC . '/blocks/image.php'; require ABSPATH . WPINC . '/blocks/latest-comments.php'; require ABSPATH . WPINC . '/blocks/latest-posts.php'; require ABSPATH . WPINC . '/blocks/legacy-widget.php'; @@ -64,11 +66,9 @@ function register_core_block_types_from_metadata() { 'cover', 'embed', 'freeform', - 'gallery', 'group', 'heading', 'html', - 'image', 'list', 'media-text', 'missing', diff --git a/tools/webpack/blocks.js b/tools/webpack/blocks.js index bbdf8f1d4c27e..2579ce11d4860 100644 --- a/tools/webpack/blocks.js +++ b/tools/webpack/blocks.js @@ -28,6 +28,8 @@ module.exports = function( env = { environment: 'production', watch: false, buil 'calendar', 'categories', 'file', + 'gallery', + 'image', 'latest-comments', 'latest-posts', 'loginout', @@ -73,11 +75,9 @@ module.exports = function( env = { environment: 'production', watch: false, buil 'cover', 'embed', 'freeform', - 'gallery', 'group', 'heading', 'html', - 'image', 'list', 'media-text', 'missing', From 4ff308580d95a374b432a6583a58f1ec81d5976a Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Wed, 8 Dec 2021 21:26:33 +0100 Subject: [PATCH 2/3] Update _unhook_block_registration() --- tests/phpunit/includes/functions.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/phpunit/includes/functions.php b/tests/phpunit/includes/functions.php index 323043dfba305..ca921d21279cf 100644 --- a/tests/phpunit/includes/functions.php +++ b/tests/phpunit/includes/functions.php @@ -307,6 +307,8 @@ function _unhook_block_registration() { remove_action( 'init', 'register_block_core_calendar' ); remove_action( 'init', 'register_block_core_categories' ); remove_action( 'init', 'register_block_core_file' ); + remove_action( 'init', 'gutenberg_register_block_core_gallery', 20 ); + remove_action( 'init', 'register_block_core_image' ); remove_action( 'init', 'register_block_core_latest_comments' ); remove_action( 'init', 'register_block_core_latest_posts' ); remove_action( 'init', 'register_block_core_legacy_widget' ); From f6c5615cd44386d2a597d9313e7041ffc02b11d9 Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Wed, 8 Dec 2021 21:47:57 +0100 Subject: [PATCH 3/3] Add block files --- src/wp-includes/blocks/gallery.php | 52 ++++++++++++++++++++++++++++++ src/wp-includes/blocks/image.php | 42 ++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 src/wp-includes/blocks/gallery.php create mode 100644 src/wp-includes/blocks/image.php diff --git a/src/wp-includes/blocks/gallery.php b/src/wp-includes/blocks/gallery.php new file mode 100644 index 0000000000000..a9765c344323a --- /dev/null +++ b/src/wp-includes/blocks/gallery.php @@ -0,0 +1,52 @@ + $inner_block ) { + if ( 'core/image' === $inner_block['blockName'] ) { + if ( ! isset( $parsed_block['innerBlocks'][ $key ]['attrs']['data-id'] ) && isset( $inner_block['attrs']['id'] ) ) { + $parsed_block['innerBlocks'][ $key ]['attrs']['data-id'] = esc_attr( $inner_block['attrs']['id'] ); + } + } + } + } + + return $parsed_block; +} + +add_filter( 'render_block_data', 'render_block_core_gallery_data' ); + +/** + * Registers the `core/gallery` block on server. + * This render callback needs to be here + * so that the gallery styles are loaded in block-based themes. + */ +function gutenberg_register_block_core_gallery() { + register_block_type_from_metadata( + __DIR__ . '/gallery', + array( + 'render_callback' => function ( $attributes, $content ) { + return $content; + }, + ) + ); +} + +add_action( 'init', 'gutenberg_register_block_core_gallery', 20 ); diff --git a/src/wp-includes/blocks/image.php b/src/wp-includes/blocks/image.php new file mode 100644 index 0000000000000..c3f22c0457155 --- /dev/null +++ b/src/wp-includes/blocks/image.php @@ -0,0 +1,42 @@ + 'render_block_core_image', + ) + ); +} +add_action( 'init', 'register_block_core_image' );