From fe59e9fc73efe6b9e6c09dda0e98e443a5e35bac Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Tue, 8 Jun 2021 15:13:01 +0300 Subject: [PATCH 1/5] [Block Library]Rename QueryLoop to PostTemplate and change Query label --- lib/block-patterns.php | 28 +++++++++---------- lib/blocks.php | 2 +- packages/block-library/src/editor.scss | 2 +- packages/block-library/src/index.js | 4 +-- .../{query-loop => post-template}/block.json | 10 +++---- .../src/{query-loop => post-template}/edit.js | 2 +- .../{query-loop => post-template}/editor.scss | 2 +- .../{query-loop => post-template}/index.js | 0 .../{query-loop => post-template}/index.php | 16 +++++------ .../src/{query-loop => post-template}/save.js | 2 +- .../{query-loop => post-template}/style.scss | 2 +- packages/block-library/src/query/block.json | 2 +- .../block-library/src/query/edit/index.js | 2 +- .../block-library/src/query/variations.js | 9 +++--- packages/block-library/src/style.scss | 2 +- packages/blocks/src/api/parser.js | 5 ++++ .../fixtures/blocks/core__post-template.html | 1 + ...ery-loop.json => core__post-template.json} | 2 +- ...d.json => core__post-template.parsed.json} | 2 +- .../core__post-template.serialized.html | 1 + .../fixtures/blocks/core__query-loop.html | 1 - .../blocks/core__query-loop.serialized.html | 1 - packages/e2e-tests/plugins/query-block.php | 8 +++--- 23 files changed, 56 insertions(+), 50 deletions(-) rename packages/block-library/src/{query-loop => post-template}/block.json (60%) rename packages/block-library/src/{query-loop => post-template}/edit.js (98%) rename packages/block-library/src/{query-loop => post-template}/editor.scss (75%) rename packages/block-library/src/{query-loop => post-template}/index.js (100%) rename packages/block-library/src/{query-loop => post-template}/index.php (83%) rename packages/block-library/src/{query-loop => post-template}/save.js (73%) rename packages/block-library/src/{query-loop => post-template}/style.scss (95%) create mode 100644 packages/e2e-tests/fixtures/blocks/core__post-template.html rename packages/e2e-tests/fixtures/blocks/{core__query-loop.json => core__post-template.json} (79%) rename packages/e2e-tests/fixtures/blocks/{core__query-loop.parsed.json => core__post-template.parsed.json} (69%) create mode 100644 packages/e2e-tests/fixtures/blocks/core__post-template.serialized.html delete mode 100644 packages/e2e-tests/fixtures/blocks/core__query-loop.html delete mode 100644 packages/e2e-tests/fixtures/blocks/core__query-loop.serialized.html diff --git a/lib/block-patterns.php b/lib/block-patterns.php index 3756d6db20a1fb..2e75cbe4ba98a0 100644 --- a/lib/block-patterns.php +++ b/lib/block-patterns.php @@ -21,7 +21,7 @@ function register_gutenberg_patterns() { 'categories' => array( 'query' ), 'content' => '
- + @@ -29,7 +29,7 @@ function register_gutenberg_patterns() {
- +
', ), @@ -39,7 +39,7 @@ function register_gutenberg_patterns() { 'categories' => array( 'query' ), 'content' => '
- +
@@ -49,7 +49,7 @@ function register_gutenberg_patterns() {
- + ', ), @@ -59,7 +59,7 @@ function register_gutenberg_patterns() { 'categories' => array( 'query' ), 'content' => '
- +
@@ -68,7 +68,7 @@ function register_gutenberg_patterns() {
- +
', ), @@ -78,13 +78,13 @@ function register_gutenberg_patterns() { 'categories' => array( 'query' ), 'content' => '
- +
- + ', ), @@ -94,7 +94,7 @@ function register_gutenberg_patterns() { 'categories' => array( 'query' ), 'content' => '
-
+

@@ -108,7 +108,7 @@ function register_gutenberg_patterns() {
-
+
', ), @@ -120,26 +120,26 @@ function register_gutenberg_patterns() {
-
+
-
+
-
+
-
+
diff --git a/lib/blocks.php b/lib/blocks.php index 68d3404a589e9c..e04842e8a9445f 100644 --- a/lib/blocks.php +++ b/lib/blocks.php @@ -102,7 +102,7 @@ function gutenberg_reregister_core_block_types() { 'post-navigation-link.php' => 'core/post-navigation-link', 'post-title.php' => 'core/post-title', 'query.php' => 'core/query', - 'query-loop.php' => 'core/query-loop', + 'post-template.php' => 'core/post-template', 'query-title.php' => 'core/query-title', 'query-pagination.php' => 'core/query-pagination', 'query-pagination-next.php' => 'core/query-pagination-next', diff --git a/packages/block-library/src/editor.scss b/packages/block-library/src/editor.scss index cef09dbb86549b..4118213572e232 100644 --- a/packages/block-library/src/editor.scss +++ b/packages/block-library/src/editor.scss @@ -46,7 +46,7 @@ @import "./text-columns/editor.scss"; @import "./video/editor.scss"; @import "./query-title/editor.scss"; -@import "./query-loop/editor.scss"; +@import "./post-template/editor.scss"; @import "./query/editor.scss"; @import "./query-pagination/editor.scss"; @import "./query-pagination-numbers/editor.scss"; diff --git a/packages/block-library/src/index.js b/packages/block-library/src/index.js index b0e36ae6dba9e7..73713305c10308 100644 --- a/packages/block-library/src/index.js +++ b/packages/block-library/src/index.js @@ -70,7 +70,7 @@ import * as siteTagline from './site-tagline'; import * as siteTitle from './site-title'; import * as templatePart from './template-part'; import * as query from './query'; -import * as queryLoop from './query-loop'; +import * as postTemplate from './post-template'; import * as queryTitle from './query-title'; import * as queryPagination from './query-pagination'; import * as queryPaginationNext from './query-pagination-next'; @@ -175,7 +175,7 @@ export const __experimentalGetCoreBlocks = () => [ siteTitle, query, - queryLoop, + postTemplate, queryTitle, queryPagination, queryPaginationNext, diff --git a/packages/block-library/src/query-loop/block.json b/packages/block-library/src/post-template/block.json similarity index 60% rename from packages/block-library/src/query-loop/block.json rename to packages/block-library/src/post-template/block.json index 1d714c2f38366d..e4d5de82815147 100644 --- a/packages/block-library/src/query-loop/block.json +++ b/packages/block-library/src/post-template/block.json @@ -1,10 +1,10 @@ { "apiVersion": 2, - "name": "core/query-loop", - "title": "Query Loop", + "name": "core/post-template", + "title": "Post Template", "category": "design", "parent": [ "core/query" ], - "description": "Query loop.", + "description": "Post Template.", "textdomain": "default", "usesContext": [ "queryId", @@ -18,6 +18,6 @@ "html": false, "align": true }, - "style": "wp-block-query-loop", - "editorStyle": "wp-block-query-loop-editor" + "style": "wp-block-post-template", + "editorStyle": "wp-block-post-template-editor" } diff --git a/packages/block-library/src/query-loop/edit.js b/packages/block-library/src/post-template/edit.js similarity index 98% rename from packages/block-library/src/query-loop/edit.js rename to packages/block-library/src/post-template/edit.js index dfb10c0b445a3a..2c8c142c2f4a0a 100644 --- a/packages/block-library/src/query-loop/edit.js +++ b/packages/block-library/src/post-template/edit.js @@ -24,7 +24,7 @@ const TEMPLATE = [ [ 'core/post-date' ], [ 'core/post-excerpt' ], ]; -export default function QueryLoopEdit( { +export default function PostTemplateEdit( { clientId, context: { query: { diff --git a/packages/block-library/src/query-loop/editor.scss b/packages/block-library/src/post-template/editor.scss similarity index 75% rename from packages/block-library/src/query-loop/editor.scss rename to packages/block-library/src/post-template/editor.scss index d0c05ad060565f..7b426b0f3d37a5 100644 --- a/packages/block-library/src/query-loop/editor.scss +++ b/packages/block-library/src/post-template/editor.scss @@ -1,5 +1,5 @@ .editor-styles-wrapper { - ul.wp-block-query-loop { + ul.wp-block-post-template { padding-left: 0; margin-left: 0; list-style: none; diff --git a/packages/block-library/src/query-loop/index.js b/packages/block-library/src/post-template/index.js similarity index 100% rename from packages/block-library/src/query-loop/index.js rename to packages/block-library/src/post-template/index.js diff --git a/packages/block-library/src/query-loop/index.php b/packages/block-library/src/post-template/index.php similarity index 83% rename from packages/block-library/src/query-loop/index.php rename to packages/block-library/src/post-template/index.php index 9bdeb13f4b81df..3daacbad7f6499 100644 --- a/packages/block-library/src/query-loop/index.php +++ b/packages/block-library/src/post-template/index.php @@ -1,12 +1,12 @@ context['queryId'] ) ? 'query-' . $block->context['queryId'] . '-page' : 'query-page'; $page = empty( $_GET[ $page_key ] ) ? 1 : (int) $_GET[ $page_key ]; @@ -74,15 +74,15 @@ function render_block_core_query_loop( $attributes, $content, $block ) { } /** - * Registers the `core/query-loop` block on the server. + * Registers the `core/post-template` block on the server. */ -function register_block_core_query_loop() { +function register_block_core_post_template() { register_block_type_from_metadata( - __DIR__ . '/query-loop', + __DIR__ . '/post-template', array( - 'render_callback' => 'render_block_core_query_loop', + 'render_callback' => 'render_block_core_post_template', 'skip_inner_blocks' => true, ) ); } -add_action( 'init', 'register_block_core_query_loop' ); +add_action( 'init', 'register_block_core_post_template' ); diff --git a/packages/block-library/src/query-loop/save.js b/packages/block-library/src/post-template/save.js similarity index 73% rename from packages/block-library/src/query-loop/save.js rename to packages/block-library/src/post-template/save.js index 25c01283865125..0533b076931602 100644 --- a/packages/block-library/src/query-loop/save.js +++ b/packages/block-library/src/post-template/save.js @@ -3,6 +3,6 @@ */ import { InnerBlocks } from '@wordpress/block-editor'; -export default function QueryLoopSave() { +export default function PostTemplateSave() { return ; } diff --git a/packages/block-library/src/query-loop/style.scss b/packages/block-library/src/post-template/style.scss similarity index 95% rename from packages/block-library/src/query-loop/style.scss rename to packages/block-library/src/post-template/style.scss index 676040b147ebbd..2db06367cf6d25 100644 --- a/packages/block-library/src/query-loop/style.scss +++ b/packages/block-library/src/post-template/style.scss @@ -1,4 +1,4 @@ -.wp-block-query-loop { +.wp-block-post-template { max-width: 100%; list-style: none; padding: 0; diff --git a/packages/block-library/src/query/block.json b/packages/block-library/src/query/block.json index b54713a75aac60..a08dbc2e1326e7 100644 --- a/packages/block-library/src/query/block.json +++ b/packages/block-library/src/query/block.json @@ -1,7 +1,7 @@ { "apiVersion": 2, "name": "core/query", - "title": "Query", + "title": "Query Loop", "category": "design", "description": "Displays a list of posts as a result of a query.", "textdomain": "default", diff --git a/packages/block-library/src/query/edit/index.js b/packages/block-library/src/query/edit/index.js index 4612033981426f..637f05c18a1be5 100644 --- a/packages/block-library/src/query/edit/index.js +++ b/packages/block-library/src/query/edit/index.js @@ -24,7 +24,7 @@ import QueryInspectorControls from './query-inspector-controls'; import QueryPlaceholder from './query-placeholder'; import { DEFAULTS_POSTS_PER_PAGE } from '../constants'; -const TEMPLATE = [ [ 'core/query-loop' ] ]; +const TEMPLATE = [ [ 'core/post-template' ] ]; export function QueryContent( { attributes, setAttributes } ) { const { queryId, diff --git a/packages/block-library/src/query/variations.js b/packages/block-library/src/query/variations.js index dbf9290cc58fc1..d5790da2048105 100644 --- a/packages/block-library/src/query/variations.js +++ b/packages/block-library/src/query/variations.js @@ -35,6 +35,7 @@ const variations = [ author: '', search: '', sticky: 'exclude', + inherit: false, }, }, scope: [ 'inserter' ], @@ -45,7 +46,7 @@ const variations = [ icon: titleDate, innerBlocks: [ [ - 'core/query-loop', + 'core/post-template', {}, [ [ 'core/post-title' ], [ 'core/post-date' ] ], ], @@ -58,7 +59,7 @@ const variations = [ icon: titleExcerpt, innerBlocks: [ [ - 'core/query-loop', + 'core/post-template', {}, [ [ 'core/post-title' ], [ 'core/post-excerpt' ] ], ], @@ -71,7 +72,7 @@ const variations = [ icon: titleDateExcerpt, innerBlocks: [ [ - 'core/query-loop', + 'core/post-template', {}, [ [ 'core/post-title' ], @@ -88,7 +89,7 @@ const variations = [ icon: imageDateTitle, innerBlocks: [ [ - 'core/query-loop', + 'core/post-template', {}, [ [ 'core/post-featured-image' ], diff --git a/packages/block-library/src/style.scss b/packages/block-library/src/style.scss index c6729fbf0eca7f..92e10a3dee23a6 100644 --- a/packages/block-library/src/style.scss +++ b/packages/block-library/src/style.scss @@ -34,7 +34,7 @@ @import "./post-title/style.scss"; @import "./preformatted/style.scss"; @import "./pullquote/style.scss"; -@import "./query-loop/style.scss"; +@import "./post-template/style.scss"; @import "./query-pagination/style.scss"; @import "./quote/style.scss"; @import "./rss/style.scss"; diff --git a/packages/blocks/src/api/parser.js b/packages/blocks/src/api/parser.js index 829557f89f2011..4ac04adca38567 100644 --- a/packages/blocks/src/api/parser.js +++ b/packages/blocks/src/api/parser.js @@ -454,6 +454,11 @@ export function convertLegacyBlocks( name, attributes ) { } name = 'core/embed'; } + + // Convert 'core/query-loop' blocks in existing content to 'core/post-template'. + if ( name === 'core/query-loop' ) { + name = 'core/post-template'; + } return { name, attributes: newAttributes }; } diff --git a/packages/e2e-tests/fixtures/blocks/core__post-template.html b/packages/e2e-tests/fixtures/blocks/core__post-template.html new file mode 100644 index 00000000000000..0664d674bdf955 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__post-template.html @@ -0,0 +1 @@ + diff --git a/packages/e2e-tests/fixtures/blocks/core__query-loop.json b/packages/e2e-tests/fixtures/blocks/core__post-template.json similarity index 79% rename from packages/e2e-tests/fixtures/blocks/core__query-loop.json rename to packages/e2e-tests/fixtures/blocks/core__post-template.json index e7edef8b5eb8c0..0b67fa4c62cb3b 100644 --- a/packages/e2e-tests/fixtures/blocks/core__query-loop.json +++ b/packages/e2e-tests/fixtures/blocks/core__post-template.json @@ -1,7 +1,7 @@ [ { "clientId": "_clientId_0", - "name": "core/query-loop", + "name": "core/post-template", "isValid": true, "attributes": {}, "innerBlocks": [], diff --git a/packages/e2e-tests/fixtures/blocks/core__query-loop.parsed.json b/packages/e2e-tests/fixtures/blocks/core__post-template.parsed.json similarity index 69% rename from packages/e2e-tests/fixtures/blocks/core__query-loop.parsed.json rename to packages/e2e-tests/fixtures/blocks/core__post-template.parsed.json index 12985d2dd36f85..f7f1fbd82e69c1 100644 --- a/packages/e2e-tests/fixtures/blocks/core__query-loop.parsed.json +++ b/packages/e2e-tests/fixtures/blocks/core__post-template.parsed.json @@ -1,6 +1,6 @@ [ { - "blockName": "core/query-loop", + "blockName": "core/post-template", "attrs": {}, "innerBlocks": [], "innerHTML": "", diff --git a/packages/e2e-tests/fixtures/blocks/core__post-template.serialized.html b/packages/e2e-tests/fixtures/blocks/core__post-template.serialized.html new file mode 100644 index 00000000000000..0664d674bdf955 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__post-template.serialized.html @@ -0,0 +1 @@ + diff --git a/packages/e2e-tests/fixtures/blocks/core__query-loop.html b/packages/e2e-tests/fixtures/blocks/core__query-loop.html deleted file mode 100644 index 16de7db3703b07..00000000000000 --- a/packages/e2e-tests/fixtures/blocks/core__query-loop.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/packages/e2e-tests/fixtures/blocks/core__query-loop.serialized.html b/packages/e2e-tests/fixtures/blocks/core__query-loop.serialized.html deleted file mode 100644 index 16de7db3703b07..00000000000000 --- a/packages/e2e-tests/fixtures/blocks/core__query-loop.serialized.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/packages/e2e-tests/plugins/query-block.php b/packages/e2e-tests/plugins/query-block.php index f985c0d772224f..46f9c363b32783 100644 --- a/packages/e2e-tests/plugins/query-block.php +++ b/packages/e2e-tests/plugins/query-block.php @@ -17,9 +17,9 @@ 'title' => __( 'Query Test 1', 'gutenberg' ), 'blockTypes' => array( 'core/query' ), 'content' => ' - + - + ', ) ); @@ -29,10 +29,10 @@ 'title' => __( 'Query Test 2', 'gutenberg' ), 'blockTypes' => array( 'core/query' ), 'content' => ' - + - + ', ) ); From ee9f247c56a38115832a8f3f1a3bf4115e1780f1 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Tue, 8 Jun 2021 15:54:13 +0300 Subject: [PATCH 2/5] keep styles for backwards compatibility for not updated existing Loop blocks --- packages/block-library/src/post-template/style.scss | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/post-template/style.scss b/packages/block-library/src/post-template/style.scss index 2db06367cf6d25..0be6b30b6903ae 100644 --- a/packages/block-library/src/post-template/style.scss +++ b/packages/block-library/src/post-template/style.scss @@ -1,4 +1,9 @@ -.wp-block-post-template { +.wp-block-post-template, +// We have kept `wp-block-query-loop` class as well for backwards +// compatibility with existing `QueryLoop` blocks that haven't been +// updated, after the renaming of the block to `Post Template`. +// See: https://github.com/WordPress/gutenberg/pull/32514. +.wp-block-query-loop { max-width: 100%; list-style: none; padding: 0; From 0940bba9b4710f4150980946676f2c4e60257e0d Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Tue, 8 Jun 2021 18:16:31 +0300 Subject: [PATCH 3/5] add server fallback for existing `QueryLoop` blocks --- .../block-library/src/post-template/index.php | 61 +++++++++++++++++++ .../src/post-template/style.scss | 1 + packages/blocks/src/api/parser.js | 1 + 3 files changed, 63 insertions(+) diff --git a/packages/block-library/src/post-template/index.php b/packages/block-library/src/post-template/index.php index 3daacbad7f6499..ebcea54d961dd8 100644 --- a/packages/block-library/src/post-template/index.php +++ b/packages/block-library/src/post-template/index.php @@ -86,3 +86,64 @@ function register_block_core_post_template() { ); } add_action( 'init', 'register_block_core_post_template' ); + + +/** + * Renders the legacy `core/query-loop` block on the server. + * It triggers a developer warning and then calls the renamed + * block's `render_callback` function output. + * + * This can be removed when WordPress 5.9 is released. + * + * @param array $attributes Block attributes. + * @param string $content Block default content. + * @param WP_Block $block Block instance. + * + * @return string Returns the output of the query, structured using the layout defined by the block's inner blocks. + */ +function render_legacy_query_loop_block( $attributes, $content, $block ) { + trigger_error( + /* translators: %1$s: Block type */ + sprintf( __( 'Block %1$s has been renamed to Post Template. %1$s will be supported until WordPress version 5.9.', 'gutenberg' ), $block->name ), + headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE + ); + return render_block_core_post_template( $attributes, $content, $block ); +} + +/** + * Complements the renaming of `Query Loop` to `Post Template`. + * This ensures backwards compatibility for any users running the Gutenberg + * plugin who have used Query Loop prior to its renaming. + * + * This can be removed when WordPress 5.9 is released. + * + * @see https://github.com/WordPress/gutenberg/pull/32514 + */ +function gutenberg_register_legacy_query_loop_block() { + $registry = WP_Block_Type_Registry::get_instance(); + if ( $registry->is_registered( 'core/query-loop' ) ) { + unregister_block_type( 'core/query-loop' ); + } + register_block_type( + 'core/query-loop', + array( + 'category' => 'design', + 'uses_context' => array( + 'queryId', + 'query', + 'queryContext', + 'displayLayout', + 'templateSlug', + ), + 'supports' => array( + 'reusable' => false, + 'html' => false, + 'align' => true, + ), + 'style' => 'wp-block-post-template', + 'render_callback' => 'render_legacy_query_loop_block', + 'skip_inner_blocks' => true, + ) + ); +} +add_action( 'wp_loaded', 'gutenberg_register_legacy_query_loop_block' ); diff --git a/packages/block-library/src/post-template/style.scss b/packages/block-library/src/post-template/style.scss index 0be6b30b6903ae..7a83a79bcb11fa 100644 --- a/packages/block-library/src/post-template/style.scss +++ b/packages/block-library/src/post-template/style.scss @@ -3,6 +3,7 @@ // compatibility with existing `QueryLoop` blocks that haven't been // updated, after the renaming of the block to `Post Template`. // See: https://github.com/WordPress/gutenberg/pull/32514. +// TODO: Remove this class when WordPress 5.9 is released. .wp-block-query-loop { max-width: 100%; list-style: none; diff --git a/packages/blocks/src/api/parser.js b/packages/blocks/src/api/parser.js index 4ac04adca38567..edffe4b4af4629 100644 --- a/packages/blocks/src/api/parser.js +++ b/packages/blocks/src/api/parser.js @@ -456,6 +456,7 @@ export function convertLegacyBlocks( name, attributes ) { } // Convert 'core/query-loop' blocks in existing content to 'core/post-template'. + // TODO: Remove this check when WordPress 5.9 is released. if ( name === 'core/query-loop' ) { name = 'core/post-template'; } From 94e389a54c75cfc084758b793b2f7df8c9282de1 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Tue, 8 Jun 2021 18:18:17 +0300 Subject: [PATCH 4/5] remove empty line --- packages/block-library/src/post-template/index.php | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/block-library/src/post-template/index.php b/packages/block-library/src/post-template/index.php index ebcea54d961dd8..cdf312cc9f1e41 100644 --- a/packages/block-library/src/post-template/index.php +++ b/packages/block-library/src/post-template/index.php @@ -87,7 +87,6 @@ function register_block_core_post_template() { } add_action( 'init', 'register_block_core_post_template' ); - /** * Renders the legacy `core/query-loop` block on the server. * It triggers a developer warning and then calls the renamed From d105a2c5ee7cadc1c89ab6ad0158056b6b6f55e2 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Tue, 8 Jun 2021 18:36:56 +0300 Subject: [PATCH 5/5] change to `init` action --- packages/block-library/src/post-template/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/post-template/index.php b/packages/block-library/src/post-template/index.php index cdf312cc9f1e41..88e029946c8308 100644 --- a/packages/block-library/src/post-template/index.php +++ b/packages/block-library/src/post-template/index.php @@ -145,4 +145,4 @@ function gutenberg_register_legacy_query_loop_block() { ) ); } -add_action( 'wp_loaded', 'gutenberg_register_legacy_query_loop_block' ); +add_action( 'init', 'gutenberg_register_legacy_query_loop_block' );