Skip to content

Commit

Permalink
Add support for search in query title
Browse files Browse the repository at this point in the history
Based on original work in WordPress#27989
  • Loading branch information
mikachan committed Jul 16, 2021
1 parent 82ec6c7 commit b2fb7d7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
3 changes: 3 additions & 0 deletions packages/block-library/src/query-title/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"description": "Display the query title.",
"textdomain": "default",
"attributes": {
"content": {
"type": "string"
},
"type": {
"type": "string"
},
Expand Down
20 changes: 18 additions & 2 deletions packages/block-library/src/query-title/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
BlockControls,
useBlockProps,
Warning,
RichText,
} from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';

Expand All @@ -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 }`;
Expand All @@ -48,6 +49,21 @@ export default function QueryTitleEdit( {
titleElement = (
<TagName { ...blockProps }>{ __( 'Archive title' ) }</TagName>
);
} else {
titleElement = (
<div { ...blockProps }>
<RichText
tagName={ TagName }
value={ content }
placeholder={ __( 'Query title' ) }
allowedFormats={ [ 'core/bold', 'core/italic' ] }
onChange={ ( newContent ) =>
setAttributes( { content: newContent } )
}
disableLineBreaks={ true }
/>
</div>
);
}
return (
<>
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/query-title/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
5 changes: 3 additions & 2 deletions packages/block-library/src/query-title/variations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
),
Expand All @@ -31,7 +32,7 @@ const variations = [
'search template title'
),
},
scope: [ 'inserter', 'transform' ],
scope: [ 'inserter' ],
},
];

Expand Down

0 comments on commit b2fb7d7

Please sign in to comment.