PluginProbe
Gutenberg / 12.1.0
Gutenberg v12.1.0
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / build / block-library / blocks / gallery.php

gallery.php in Gutenberg 12.1.0, at build/block-library/blocks/gallery.php

53 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Server-side rendering of the `core/image` block.
4 *
5 * @package WordPress
6 */
7
8 /**
9 * Handles backwards compatibility for Gallery Blocks,
10 * whose images feature a `data-id` attribute.
11 *
12 * Now that the Gallery Block contains inner Image Blocks,
13 * we add a custom `data-id` attribute before rendering the gallery
14 * so that the Image Block can pick it up in its render_callback.
15 *
16 * @param array $parsed_block A single parsed block object.
17 *
18 * @return array The migrated block object.
19 */
20 function gutenberg_render_block_core_gallery_data( $parsed_block ) {
21 if ( 'core/gallery' === $parsed_block['blockName'] ) {
22 foreach ( $parsed_block['innerBlocks'] as $key => $inner_block ) {
23 if ( 'core/image' === $inner_block['blockName'] ) {
24 if ( ! isset( $parsed_block['innerBlocks'][ $key ]['attrs']['data-id'] ) && isset( $inner_block['attrs']['id'] ) ) {
25 $parsed_block['innerBlocks'][ $key ]['attrs']['data-id'] = esc_attr( $inner_block['attrs']['id'] );
26 }
27 }
28 }
29 }
30
31 return $parsed_block;
32 }
33
34 add_filter( 'render_block_data', 'gutenberg_render_block_core_gallery_data' );
35
36 /**
37 * Registers the `core/gallery` block on server.
38 * This render callback needs to be here
39 * so that the gallery styles are loaded in block-based themes.
40 */
41 function gutenberg_gutenberg_register_block_core_gallery() {
42 register_block_type_from_metadata(
43 __DIR__ . '/gallery',
44 array(
45 'render_callback' => function ( $attributes, $content ) {
46 return $content;
47 },
48 )
49 );
50 }
51
52 add_action( 'init', 'gutenberg_gutenberg_register_block_core_gallery', 20 );
53