-
Notifications
You must be signed in to change notification settings - Fork 42
Closed
Description
Is your enhancement related to a problem? Please describe.
Gaining for greater flexibility, I'd like us to encourage the Block Hooks API to add all of the GatherPress blocks into templates.
Following on, with what I wrote at #626
Therefore GatherPress registers two invisible block patterns, that are used as template properties of the main post types.
- Within my exploration I changed the
templateproperty to the following:
'template' => array(
// array( 'gatherpress/venue' ),
array( 'core/pattern', array( 'slug' => 'gatherpress/venue-details' ) ),
),- The called pattern looks like this and will not be visible to the editor at any point:
\register_block_pattern( 'gatherpress/venue-details',
array(
'title' => 'Invisible Venue Details Block Pattern', // no i18n needed
'content' => '', // this will a be hooked ;)
'inserter' => false,
'source' => 'plugin',
)
);- Now any block - inside and outside of the GatherPress plugin - can easily declare:
add_filter( 'hooked_block_types', __NAMESPACE__ . '\\hook_block_into_pattern', 10, 4 );
function hook_block_into_pattern( $hooked_block_types, $relative_position, $anchor_block_type, $context ) {
if (
// Conditionally hook the block into the "gatherpress/venue-details" pattern.
is_array( $context ) &&
isset( $context[ 'name' ] ) &&
'gatherpress/venue-details' === $context[ 'name' ]
) {
$hooked_block_types[] = 'gatherpress/rsvp';
}
return $hooked_block_types;
}- It just gets a little messy when it comes to block variations, that use the Block Bindings API under the hood.
Designs
No response
Describe alternatives you've considered
No response
Code of Conduct
- I agree to follow this project's Code of Conduct
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done