From b2fb7d7216c35cb22610fc3b7b87b57e28196ac6 Mon Sep 17 00:00:00 2001 From: Sarah Norris Date: Fri, 16 Jul 2021 11:31:31 +0100 Subject: [PATCH] Add support for search in query title Based on original work in #27989 --- .../block-library/src/query-title/block.json | 3 +++ .../block-library/src/query-title/edit.js | 20 +++++++++++++++++-- .../block-library/src/query-title/index.php | 2 +- .../src/query-title/variations.js | 5 +++-- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/packages/block-library/src/query-title/block.json b/packages/block-library/src/query-title/block.json index 3e5d43fc50846d..a913d79164a834 100644 --- a/packages/block-library/src/query-title/block.json +++ b/packages/block-library/src/query-title/block.json @@ -6,6 +6,9 @@ "description": "Display the query title.", "textdomain": "default", "attributes": { + "content": { + "type": "string" + }, "type": { "type": "string" }, diff --git a/packages/block-library/src/query-title/edit.js b/packages/block-library/src/query-title/edit.js index c90c2627812ca4..6a561c338c3f95 100644 --- a/packages/block-library/src/query-title/edit.js +++ b/packages/block-library/src/query-title/edit.js @@ -12,6 +12,7 @@ import { BlockControls, useBlockProps, Warning, + RichText, } from '@wordpress/block-editor'; import { __ } from '@wordpress/i18n'; @@ -20,10 +21,10 @@ import { __ } from '@wordpress/i18n'; */ import HeadingLevelDropdown from '../heading/heading-level-dropdown'; -const SUPPORTED_TYPES = [ 'archive' ]; +const SUPPORTED_TYPES = [ 'archive', 'search' ]; export default function QueryTitleEdit( { - attributes: { type, level, textAlign }, + attributes: { content, type, level, textAlign }, setAttributes, } ) { const TagName = `h${ level }`; @@ -48,6 +49,21 @@ export default function QueryTitleEdit( { titleElement = ( { __( 'Archive title' ) } ); + } else { + titleElement = ( +
+ + setAttributes( { content: newContent } ) + } + disableLineBreaks={ true } + /> +
+ ); } return ( <> diff --git a/packages/block-library/src/query-title/index.php b/packages/block-library/src/query-title/index.php index 5822b6604f7159..11b82398d361e4 100644 --- a/packages/block-library/src/query-title/index.php +++ b/packages/block-library/src/query-title/index.php @@ -21,7 +21,7 @@ function render_block_core_query_title( $attributes ) { if ( ! $type || ( 'archive' === $type && ! $is_archive ) || ( 'search' === $type && ! $is_search ) ) { return ''; } - $title = ''; + $title = isset( $attributes['content'] ) ? $attributes['content'] : ''; if ( $is_archive ) { $title = get_the_archive_title(); } diff --git a/packages/block-library/src/query-title/variations.js b/packages/block-library/src/query-title/variations.js index 89346f20387bea..e2e7ec323de60a 100644 --- a/packages/block-library/src/query-title/variations.js +++ b/packages/block-library/src/query-title/variations.js @@ -14,12 +14,13 @@ const variations = [ icon: archiveTitle, attributes: { type: 'archive', + content: __( 'Archive title' ), }, scope: [ 'inserter' ], }, { name: 'search-title', - title: __( 'Search title' ), + title: __( 'Search Title' ), description: __( 'Displays a title in a search template, using search related format placeholders.' ), @@ -31,7 +32,7 @@ const variations = [ 'search template title' ), }, - scope: [ 'inserter', 'transform' ], + scope: [ 'inserter' ], }, ];