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

Edit Site: Fix Template Part Auto-draft creation #23050

Merged
merged 1 commit into from
Jun 10, 2020
Merged
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
9 changes: 4 additions & 5 deletions lib/template-loader.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -134,10 +134,9 @@ function gutenberg_override_query_template( $template, $type, array $templates =
* @return int[] A list of template parts IDs for the given block. * @return int[] A list of template parts IDs for the given block.
*/ */
function create_auto_draft_for_template_part_block( $block ) { function create_auto_draft_for_template_part_block( $block ) {
if ( 'core/template-part' !== $block['blockName'] ) { $template_part_ids = array();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need to be an array.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the alternative? 🤔 It seemed like the most straight-forward way to allow for the inner blocks recursion to conditionally extend it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I just expected it to be added to the array at the end instead of declaring itself as an array, but I can see how that can be more complicated in PHP.

return array();
}


if ( 'core/template-part' === $block['blockName'] ) {
if ( isset( $block['attrs']['postId'] ) ) { if ( isset( $block['attrs']['postId'] ) ) {
// Template part is customized. // Template part is customized.
$template_part_id = $block['attrs']['postId']; $template_part_id = $block['attrs']['postId'];
Expand Down Expand Up @@ -193,8 +192,8 @@ function create_auto_draft_for_template_part_block( $block ) {
); );
} }
} }

$template_part_ids[ $block['attrs']['slug'] ] = $template_part_id;
$template_part_ids = array( $block['attrs']['slug'] => $template_part_id ); }


foreach ( $block['innerBlocks'] as $inner_block ) { foreach ( $block['innerBlocks'] as $inner_block ) {
$template_part_ids = array_merge( $template_part_ids, create_auto_draft_for_template_part_block( $inner_block ) ); $template_part_ids = array_merge( $template_part_ids, create_auto_draft_for_template_part_block( $inner_block ) );
Expand Down