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

Fix docs and function naming for gallery block registration in PHP #37132

Merged
merged 4 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 7 additions & 8 deletions packages/block-library/src/gallery/index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Server-side rendering of the `core/image` block.
* Server-side rendering of the `core/gallery` block.
*
* @package WordPress
*/
Expand All @@ -13,11 +13,10 @@
* we add a custom `data-id` attribute before rendering the gallery
* so that the Image Block can pick it up in its render_callback.
*
* @param array $parsed_block A single parsed block object.
*
* @return array The migrated block object.
* @param array $parsed_block The block being rendered.
* @return array The migrated block object.
*/
function render_block_core_gallery_data( $parsed_block ) {
function block_core_gallery_data_id_backcompatibility( $parsed_block ) {
if ( 'core/gallery' === $parsed_block['blockName'] ) {
foreach ( $parsed_block['innerBlocks'] as $key => $inner_block ) {
if ( 'core/image' === $inner_block['blockName'] ) {
Expand All @@ -31,14 +30,14 @@ function render_block_core_gallery_data( $parsed_block ) {
return $parsed_block;
}

add_filter( 'render_block_data', 'render_block_core_gallery_data' );
add_filter( 'render_block_data', 'block_core_gallery_data_id_backcompatibility' );

/**
* 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() {
function register_block_core_gallery() {
register_block_type_from_metadata(
__DIR__ . '/gallery',
array(
Expand All @@ -49,4 +48,4 @@ function gutenberg_register_block_core_gallery() {
);
}

add_action( 'init', 'gutenberg_register_block_core_gallery', 20 );
add_action( 'init', 'register_block_core_gallery', 20 );
2 changes: 1 addition & 1 deletion packages/block-library/src/image/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*
* @param array $attributes The block attributes.
* @param array $content The block content.
* @return string Returns the block content with the data-id attribute added.
* @return string Returns the block content with the data-id attribute added.
*/
function render_block_core_image( $attributes, $content ) {
if ( isset( $attributes['data-id'] ) ) {
Expand Down