PluginProbe
Gutenberg / 12.7.1
Gutenberg v12.7.1
24.0.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 All 403 releases
gutenberg / build / block-library / blocks / gallery.php

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

45 lines 1.3 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/gallery` 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 The block being rendered.
17 * @return array The migrated block object.
18 */
19 function gutenberg_block_core_gallery_data_id_backcompatibility( $parsed_block ) {
20 if ( 'core/gallery' === $parsed_block['blockName'] ) {
21 foreach ( $parsed_block['innerBlocks'] as $key => $inner_block ) {
22 if ( 'core/image' === $inner_block['blockName'] ) {
23 if ( ! isset( $parsed_block['innerBlocks'][ $key ]['attrs']['data-id'] ) && isset( $inner_block['attrs']['id'] ) ) {
24 $parsed_block['innerBlocks'][ $key ]['attrs']['data-id'] = esc_attr( $inner_block['attrs']['id'] );
25 }
26 }
27 }
28 }
29
30 return $parsed_block;
31 }
32
33 add_filter( 'render_block_data', 'gutenberg_block_core_gallery_data_id_backcompatibility' );
34
35 /**
36 * Registers the `core/gallery` block on server.
37 */
38 function gutenberg_register_block_core_gallery() {
39 register_block_type_from_metadata(
40 __DIR__ . '/gallery'
41 );
42 }
43
44 add_action( 'init', 'gutenberg_register_block_core_gallery', 20 );
45