Skip to content

Commit

Permalink
Dotcom Patterns: Register wp_block patterns from Dotcompatterns with …
Browse files Browse the repository at this point in the history
…blockTypes (#35337)

* Register wp_block patterns from Dotcompatterns with blockTypes

* changelog

* Update project version

* Updated composer lock
  • Loading branch information
miksansegundo committed Jan 30, 2024
1 parent 38383ae commit 948b3dd
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Register wp_block patterns from Dotcompatterns with blockTypes
2 changes: 1 addition & 1 deletion projects/packages/jetpack-mu-wpcom/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
},
"autotagger": true,
"branch-alias": {
"dev-trunk": "5.11.x-dev"
"dev-trunk": "5.12.x-dev"
},
"textdomain": "jetpack-mu-wpcom",
"version-constants": {
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/jetpack-mu-wpcom/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-mu-wpcom",
"version": "5.11.1-alpha",
"version": "5.12.0-alpha",
"description": "Enhances your site with features powered by WordPress.com",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/jetpack-mu-wpcom/#readme",
"bugs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Jetpack_Mu_Wpcom main class.
*/
class Jetpack_Mu_Wpcom {
const PACKAGE_VERSION = '5.11.1-alpha';
const PACKAGE_VERSION = '5.12.0-alpha';
const PKG_DIR = __DIR__ . '/../';
const BASE_DIR = __DIR__ . '/';
const BASE_FILE = __FILE__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ function ( $a, $b ) {
$viewport_width = $viewport_width < 320 ? 320 : $viewport_width;
$pattern_name = self::PATTERN_NAMESPACE . $pattern['name'];
$block_types = $this->utils->maybe_get_pattern_block_types_from_pattern_meta( $pattern );
if ( empty( $block_types ) ) {
// For wp_block patterns because don't use pattern meta for block types.
$block_types = $this->utils->get_block_types_from_categories( $pattern );
}

$results[ $pattern_name ] = register_block_pattern(
$pattern_name,
Expand Down Expand Up @@ -180,7 +184,7 @@ private function get_patterns( $patterns_cache_key, $patterns_source ) {
if ( $enable_testing_v2_patterns || false === $block_patterns || ( defined( 'WP_DISABLE_PATTERN_CACHE' ) && WP_DISABLE_PATTERN_CACHE ) ) {
if ( $enable_testing_v2_patterns ) {
$request_params = array(
'site' => 'assemblerv2patterns.wordpress.com',
'site' => 'dotcompatterns.wordpress.com',
'post_type' => 'wp_block',
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,38 @@ public function maybe_get_pattern_block_types_from_pattern_meta( $pattern ) {
return $block_types;
}

/**
* Using the pattern categories, generate the `blockTypes` property for
* registering the pattern via `register_block_pattern`.
*
* @param array $pattern A pattern with categories.
*
* @return array An array of block types.
*/
public function get_block_types_from_categories( $pattern ) {
$block_types = array();

if ( ! isset( $pattern['categories'] ) || empty( $pattern['categories'] ) ) {
return $block_types;
}

foreach ( $pattern['categories'] as $key => $value ) {
switch ( $key ) {
case 'header':
$block_types[] = 'core/template-part/header';
break;
case 'footer':
$block_types[] = 'core/template-part/footer';
break;
case 'posts':
$block_types[] = 'core/query';
break;
}
}

return $block_types;
}

/**
* Return pattern post types based on the pattern's blockTypes.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/mu-wpcom-plugin/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 948b3dd

Please sign in to comment.