Make WordPress Core

Opened 2 weeks ago

Closed 2 weeks ago

Last modified 2 weeks ago

#62901 closed defect (bug) (fixed)

Editor: Fix 'parents' argument validation for Query block

Reported by: mamaduka's profile Mamaduka Owned by: mamaduka's profile Mamaduka
Milestone: 6.8 Priority: normal
Severity: normal Version:
Component: Editor Keywords: has-patch commit
Focuses: Cc:

Description

The build_query_vars_from_query_block doesn't allow specifying zero (0) in the parent's array argument, which can be used to display on top-level pages.

Gutenberg PR: https://github.com/WordPress/gutenberg/pull/68983.

Change History (6)

@peterwilsoncc commented on PR #8245:


2 weeks ago
#2

This looks good to me, I used the following to test it against trunk and this branch and it now behaves as expected. Are you able to put this in to the test suite?

/**
 * @ticket 62901
 */
public function test_build_query_vars_from_query_block_with_top_level_parent() {
        $this->registry->register(
                'core/example',
                array( 'uses_context' => array( 'query' ) )
        );

        $parsed_blocks = parse_blocks( 'ab' );
        $parsed_block  = $parsed_blocks[0];
        $context       = array(
                'query' => array(
                        'postType' => 'page',
                        'parents'  => array( 0 ),
                ),
        );
        $block         = new WP_Block( $parsed_block, $context, $this->registry );
        $query         = build_query_vars_from_query_block( $block, 1 );

        $this->assertSame(
                array(
                        'post_type'       => 'page',
                        'order'           => 'DESC',
                        'orderby'         => 'date',
                        'post__not_in'    => array(),
                        'tax_query'       => array(),
                        'post_parent__in' => array( 0 ),
                ),
                $query
        );
}

@Mamaduka commented on PR #8245:


2 weeks ago
#3

Thank you, @peterwilsoncc!

#4 @audrasjb
2 weeks ago

  • Keywords commit added

@Mamaduka I'm fine with the changeset + the related unit test case 👍

#5 @Mamaduka
2 weeks ago

  • Owner set to Mamaduka
  • Resolution set to fixed
  • Status changed from new to closed

In 59761:

Editor: Fix parents argument validation for Query block.

Allow passing zero (0) via the parents argument. It is a valid value for hierarchical post types, often used to display top-level items.

Props mamaduka, audrasjb, peterwilsoncc.
Fixes #62901.

Note: See TracTickets for help on using tickets.