Skip to content

Commit

Permalink
Fix docs and function naming for gallery block registration in PHP (#…
Browse files Browse the repository at this point in the history
…37132)

* Docs: Don't align @param and @return tags

* Remove gutenberg_ prefix for register_block_core_gallery()

* Fix typo and docs formatting

* Rename function for clarity and to match similar functions

Example: block_core_navigation_typographic_presets_backcompatibility()
  • Loading branch information
ocean90 authored and noisysocks committed Dec 13, 2021
1 parent e67a939 commit e5d4813
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
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

0 comments on commit e5d4813

Please sign in to comment.