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

[Block Library]Rename QueryLoop to PostTemplate and change Query label #32514

Merged
merged 5 commits into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions lib/block-patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ function register_gutenberg_patterns() {
'categories' => array( 'query' ),
'content' => '<!-- wp:query {"query":{"perPage":1,"pages":0,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":false}} -->
<div class="wp-block-query">
<!-- wp:query-loop -->
<!-- wp:post-template -->
<!-- wp:post-title {"isLink":true} /-->
<!-- wp:post-featured-image {"isLink":true,"align":"wide"} /-->
<!-- wp:post-excerpt /-->
<!-- wp:separator -->
<hr class="wp-block-separator"/>
<!-- /wp:separator -->
<!-- wp:post-date /-->
<!-- /wp:query-loop -->
<!-- /wp:post-template -->
</div>
<!-- /wp:query -->',
),
Expand All @@ -39,7 +39,7 @@ function register_gutenberg_patterns() {
'categories' => array( 'query' ),
'content' => '<!-- wp:query {"query":{"perPage":1,"pages":0,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":false}} -->
<div class="wp-block-query">
<!-- wp:query-loop -->
<!-- wp:post-template -->
<!-- wp:columns {"align":"wide"} -->
<div class="wp-block-columns alignwide"><!-- wp:column {"width":"66.66%"} -->
<div class="wp-block-column" style="flex-basis:66.66%"><!-- wp:post-featured-image {"isLink":true} /--></div>
Expand All @@ -49,7 +49,7 @@ function register_gutenberg_patterns() {
<!-- wp:post-excerpt /--></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->
<!-- /wp:query-loop -->
<!-- /wp:post-template -->
</div>
<!-- /wp:query -->',
),
Expand All @@ -59,7 +59,7 @@ function register_gutenberg_patterns() {
'categories' => array( 'query' ),
'content' => '<!-- wp:query {"query":{"perPage":1,"pages":0,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":false}} -->
<div class="wp-block-query">
<!-- wp:query-loop -->
<!-- wp:post-template -->
<!-- wp:columns {"verticalAlignment":"center"} -->
<div class="wp-block-columns are-vertically-aligned-center"><!-- wp:column {"verticalAlignment":"center","width":"25%"} -->
<div class="wp-block-column is-vertically-aligned-center" style="flex-basis:25%"><!-- wp:post-featured-image {"isLink":true} /--></div>
Expand All @@ -68,7 +68,7 @@ function register_gutenberg_patterns() {
<div class="wp-block-column is-vertically-aligned-center" style="flex-basis:75%"><!-- wp:post-title {"isLink":true} /--></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->
<!-- /wp:query-loop -->
<!-- /wp:post-template -->
</div>
<!-- /wp:query -->',
),
Expand All @@ -78,13 +78,13 @@ function register_gutenberg_patterns() {
'categories' => array( 'query' ),
'content' => '<!-- wp:query {"query":{"perPage":6,"pages":0,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"exclude","inherit":false},"displayLayout":{"type":"flex","columns":3}} -->
<div class="wp-block-query">
<!-- wp:query-loop -->
<!-- wp:post-template -->
<!-- wp:group {"tagName":"main","style":{"spacing":{"padding":{"top":"30px","right":"30px","bottom":"30px","left":"30px"}}},"layout":{"inherit":false}} -->
<main class="wp-block-group" style="padding-top:30px;padding-right:30px;padding-bottom:30px;padding-left:30px"><!-- wp:post-title {"isLink":true} /-->
<!-- wp:post-excerpt {"wordCount":20} /-->
<!-- wp:post-date /--></div>
<!-- /wp:group -->
<!-- /wp:query-loop -->
<!-- /wp:post-template -->
</div>
<!-- /wp:query -->',
),
Expand All @@ -94,7 +94,7 @@ function register_gutenberg_patterns() {
'categories' => array( 'query' ),
'content' => '<!-- wp:group {"align":"full","style":{"spacing":{"padding":{"top":"100px","right":"100px","bottom":"100px","left":"100px"}},"color":{"text":"#ffffff","background":"#000000"}}} -->
<div class="wp-block-group alignfull has-text-color has-background" style="background-color:#000000;color:#ffffff;padding-top:100px;padding-right:100px;padding-bottom:100px;padding-left:100px"><!-- wp:query {"query":{"perPage":3,"pages":0,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":false}} -->
<div class="wp-block-query"><!-- wp:query-loop -->
<div class="wp-block-query"><!-- wp:post-template -->
<!-- wp:separator {"customColor":"#ffffff","align":"wide","className":"is-style-wide"} -->
<hr class="wp-block-separator alignwide has-text-color has-background is-style-wide" style="background-color:#ffffff;color:#ffffff"/>
<!-- /wp:separator -->
Expand All @@ -108,7 +108,7 @@ function register_gutenberg_patterns() {
<div class="wp-block-column is-vertically-aligned-center" style="flex-basis:80%"><!-- wp:post-title {"isLink":true,"style":{"typography":{"fontSize":"72px","lineHeight":"1.1"},"color":{"text":"#ffffff","link":"#ffffff"}}} /--></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->
<!-- /wp:query-loop --></div>
<!-- /wp:post-template --></div>
<!-- /wp:query --></div>
<!-- /wp:group -->',
),
Expand All @@ -120,26 +120,26 @@ function register_gutenberg_patterns() {
<main class="wp-block-group" style="padding-top:30px;padding-right:30px;padding-bottom:30px;padding-left:30px"><!-- wp:columns -->
<div class="wp-block-columns"><!-- wp:column {"width":"50%"} -->
<div class="wp-block-column" style="flex-basis:50%"><!-- wp:query {"query":{"perPage":2,"pages":0,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"exclude","inherit":false},"displayLayout":{"type":"list"}} -->
<div class="wp-block-query"><!-- wp:query-loop -->
<div class="wp-block-query"><!-- wp:post-template -->
<!-- wp:post-featured-image /-->
<!-- wp:post-title /-->
<!-- wp:post-date /-->
<!-- wp:spacer {"height":200} -->
<div style="height:200px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->
<!-- /wp:query-loop --></div>
<!-- /wp:post-template --></div>
<!-- /wp:query --></div>
<!-- /wp:column -->
<!-- wp:column {"width":"50%"} -->
<div class="wp-block-column" style="flex-basis:50%"><!-- wp:query {"query":{"perPage":2,"pages":0,"offset":2,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"exclude","inherit":false},"displayLayout":{"type":"list"}} -->
<div class="wp-block-query"><!-- wp:query-loop -->
<div class="wp-block-query"><!-- wp:post-template -->
<!-- wp:spacer {"height":200} -->
<div style="height:200px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->
<!-- wp:post-featured-image /-->
<!-- wp:post-title /-->
<!-- wp:post-date /-->
<!-- /wp:query-loop --></div>
<!-- /wp:post-template --></div>
<!-- /wp:query --></div>
<!-- /wp:column --></div>
<!-- /wp:columns --></main>
Expand Down
2 changes: 1 addition & 1 deletion lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -175,7 +175,7 @@ export const __experimentalGetCoreBlocks = () => [
siteTitle,

query,
queryLoop,
postTemplate,
queryTitle,
queryPagination,
queryPaginationNext,
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const TEMPLATE = [
[ 'core/post-date' ],
[ 'core/post-excerpt' ],
];
export default function QueryLoopEdit( {
export default function PostTemplateEdit( {
clientId,
context: {
query: {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?php
/**
* Server-side rendering of the `core/query-loop` block.
* Server-side rendering of the `core/post-template` block.
*
* @package WordPress
*/

/**
* Renders the `core/query-loop` block on the server.
* Renders the `core/post-template` block on the server.
*
* @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_block_core_query_loop( $attributes, $content, $block ) {
function render_block_core_post_template( $attributes, $content, $block ) {
$page_key = isset( $block->context['queryId'] ) ? 'query-' . $block->context['queryId'] . '-page' : 'query-page';
$page = empty( $_GET[ $page_key ] ) ? 1 : (int) $_GET[ $page_key ];

Expand Down Expand Up @@ -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' );
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
*/
import { InnerBlocks } from '@wordpress/block-editor';

export default function QueryLoopSave() {
export default function PostTemplateSave() {
return <InnerBlocks.Content />;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.wp-block-query-loop {
.wp-block-post-template {
max-width: 100%;
list-style: none;
padding: 0;
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/query/block.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/query/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 5 additions & 4 deletions packages/block-library/src/query/variations.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const variations = [
author: '',
search: '',
sticky: 'exclude',
inherit: false,
},
},
scope: [ 'inserter' ],
Expand All @@ -45,7 +46,7 @@ const variations = [
icon: titleDate,
innerBlocks: [
[
'core/query-loop',
'core/post-template',
{},
[ [ 'core/post-title' ], [ 'core/post-date' ] ],
],
Expand All @@ -58,7 +59,7 @@ const variations = [
icon: titleExcerpt,
innerBlocks: [
[
'core/query-loop',
'core/post-template',
{},
[ [ 'core/post-title' ], [ 'core/post-excerpt' ] ],
],
Expand All @@ -71,7 +72,7 @@ const variations = [
icon: titleDateExcerpt,
innerBlocks: [
[
'core/query-loop',
'core/post-template',
{},
[
[ 'core/post-title' ],
Expand All @@ -88,7 +89,7 @@ const variations = [
icon: imageDateTitle,
innerBlocks: [
[
'core/query-loop',
'core/post-template',
{},
[
[ 'core/post-featured-image' ],
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
5 changes: 5 additions & 0 deletions packages/blocks/src/api/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,11 @@ export function convertLegacyBlocks( name, attributes ) {
}
name = 'core/embed';
}

// Convert 'core/query-loop' blocks in existing content to 'core/post-template'.
ntsekouras marked this conversation as resolved.
Show resolved Hide resolved
if ( name === 'core/query-loop' ) {
name = 'core/post-template';
}
return { name, attributes: newAttributes };
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- wp:post-template /-->
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"clientId": "_clientId_0",
"name": "core/query-loop",
"name": "core/post-template",
"isValid": true,
"attributes": {},
"innerBlocks": [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"blockName": "core/query-loop",
"blockName": "core/post-template",
"attrs": {},
"innerBlocks": [],
"innerHTML": "",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- wp:post-template /-->
1 change: 0 additions & 1 deletion packages/e2e-tests/fixtures/blocks/core__query-loop.html

This file was deleted.

This file was deleted.

8 changes: 4 additions & 4 deletions packages/e2e-tests/plugins/query-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
'title' => __( 'Query Test 1', 'gutenberg' ),
'blockTypes' => array( 'core/query' ),
'content' => '<!-- wp:query {"query":{"perPage":1,"pages":0,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":true}} -->
<!-- wp:query-loop -->
<!-- wp:post-template -->
<!-- wp:post-title {"isLink":true} /-->
<!-- /wp:query-loop -->
<!-- /wp:post-template -->
<!-- /wp:query -->',
)
);
Expand All @@ -29,10 +29,10 @@
'title' => __( 'Query Test 2', 'gutenberg' ),
'blockTypes' => array( 'core/query' ),
'content' => '<!-- wp:query {"query":{"perPage":1,"pages":0,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":true}} -->
<!-- wp:query-loop -->
<!-- wp:post-template -->
<!-- wp:post-title {"isLink":true} /-->
<!-- wp:post-date /-->
<!-- /wp:query-loop -->
<!-- /wp:post-template -->
<!-- /wp:query -->',
)
);