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

Blocks: Change get_hooked_blocks() to returned hooked blocks grouped by relative position #5296

Closed
wants to merge 1 commit into from

Conversation

ockham
Copy link
Contributor

@ockham ockham commented Sep 25, 2023

See the unit test diff to see how the return format has changed.

The main reason for doing is is that all existing calls of get_hooked_blocks in production code used to need an extra array_keys call. This seemed beside the point.

Furthermore, this allows us to remove the extra $relative_position argument from the function again, as the same data can now be simply fetched via array access.

Trac ticket: TBD


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@ockham ockham self-assigned this Sep 25, 2023
Comment on lines +808 to +812
if ( array_key_exists( $relative_position, $hooked_block_types ) ) {
$hooked_block_types = $hooked_block_types[ $relative_position ];
} else {
$hooked_block_types = 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.

These extra checks are probably the biggest downside of the suggested change (needed for each position; see below).

The alternative would be to make get_hooked_blocks create empty arrays for all positions, but I didn't like that option so much either; one drawback would be that we'd need to give get_hooked_blocks a list of possible relative positions (which we'd also need to update if we introduce new ones); whereas with the current approach, we can keep get_hooked_blocks ignorant of what relative positions exist, and let it create arrays for whatever it finds.

@ockham
Copy link
Contributor Author

ockham commented Sep 25, 2023

Uh, used the wrong remote to open the PR 🤦‍♂️ Will close and open one in my own fork.

@ockham ockham closed this Sep 25, 2023
@ockham
Copy link
Contributor Author

ockham commented Sep 25, 2023

Uh, used the wrong remote to open the PR 🤦‍♂️ Will close and open one in my own fork.

#5297

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant