diff --git a/lib/blocks.php b/lib/blocks.php index 4cd8fe50a8fd34..7e67106404952f 100644 --- a/lib/blocks.php +++ b/lib/blocks.php @@ -91,6 +91,7 @@ function gutenberg_reregister_core_block_types() { 'site-title.php' => 'core/site-title', // 'table-of-contents.php' => 'core/table-of-contents', 'template-part.php' => 'core/template-part', + 'term-description.php' => 'core/term-description', ) ), ), diff --git a/packages/block-library/src/editor.scss b/packages/block-library/src/editor.scss index 4ff3ee319d800d..9ff64efd4684e2 100644 --- a/packages/block-library/src/editor.scss +++ b/packages/block-library/src/editor.scss @@ -53,6 +53,7 @@ @import "./query-pagination/editor.scss"; @import "./query-pagination-numbers/editor.scss"; @import "./post-featured-image/editor.scss"; +@import "./term-description/editor.scss"; :root .editor-styles-wrapper { // Background colors. diff --git a/packages/block-library/src/index.js b/packages/block-library/src/index.js index c4830add9cc1a7..2268548e13d519 100644 --- a/packages/block-library/src/index.js +++ b/packages/block-library/src/index.js @@ -89,6 +89,7 @@ import * as postExcerpt from './post-excerpt'; import * as postFeaturedImage from './post-featured-image'; import * as postHierarchicalTerms from './post-hierarchical-terms'; import * as postTags from './post-tags'; +import * as termDescription from './term-description'; /** * Function to register an individual block. @@ -240,6 +241,7 @@ export const __experimentalRegisterExperimentalCoreBlocks = postHierarchicalTerms, postTags, postNavigationLink, + termDescription, ] : [] ), ].forEach( registerBlock ); diff --git a/packages/block-library/src/term-description/block.json b/packages/block-library/src/term-description/block.json new file mode 100644 index 00000000000000..b358334963994e --- /dev/null +++ b/packages/block-library/src/term-description/block.json @@ -0,0 +1,20 @@ +{ + "apiVersion": 2, + "name": "core/term-description", + "category": "design", + "attributes": { + "textAlign": { + "type": "string" + } + }, + "supports": { + "align": [ "wide", "full" ], + "html": false, + "fontSize": true, + "lineHeight": true, + "color": { + "link": true + } + }, + "editorStyle": "wp-block-term-description-editor" +} diff --git a/packages/block-library/src/term-description/edit.js b/packages/block-library/src/term-description/edit.js new file mode 100644 index 00000000000000..b4cc0a062c6dfb --- /dev/null +++ b/packages/block-library/src/term-description/edit.js @@ -0,0 +1,45 @@ +/** + * External dependencies + */ +import classnames from 'classnames'; + +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; +import { + useBlockProps, + BlockControls, + AlignmentToolbar, +} from '@wordpress/block-editor'; + +export default function TermDescriptionEdit( { + attributes, + setAttributes, + mergedStyle, +} ) { + const { textAlign } = attributes; + const blockProps = useBlockProps( { + className: classnames( { + [ `has-text-align-${ textAlign }` ]: textAlign, + } ), + style: mergedStyle, + } ); + return ( + <> + + { + setAttributes( { textAlign: nextAlign } ); + } } + /> + +
+
+ { __( 'Term description.' ) } +
+
+ + ); +} diff --git a/packages/block-library/src/term-description/editor.scss b/packages/block-library/src/term-description/editor.scss new file mode 100644 index 00000000000000..1eb196c9bfdc52 --- /dev/null +++ b/packages/block-library/src/term-description/editor.scss @@ -0,0 +1,4 @@ +.wp-block-term-description__placeholder { + padding: 1em 0; + border: 1px dashed; +} diff --git a/packages/block-library/src/term-description/index.js b/packages/block-library/src/term-description/index.js new file mode 100644 index 00000000000000..2981fc4677da7d --- /dev/null +++ b/packages/block-library/src/term-description/index.js @@ -0,0 +1,23 @@ +/** + * WordPress dependencies + */ +import { _x, __ } from '@wordpress/i18n'; +import { termDescription as icon } from '@wordpress/icons'; + +/** + * Internal dependencies + */ +import metadata from './block.json'; +import edit from './edit'; + +const { name } = metadata; +export { metadata, name }; + +export const settings = { + title: _x( 'Term Description', 'block title' ), + description: __( + 'Display the description of categories, tags and custom taxonomies when viewing an archive.' + ), + icon, + edit, +}; diff --git a/packages/block-library/src/term-description/index.php b/packages/block-library/src/term-description/index.php new file mode 100644 index 00000000000000..b7819dd3df0af8 --- /dev/null +++ b/packages/block-library/src/term-description/index.php @@ -0,0 +1,41 @@ + 'has-text-align-' . $attributes['textAlign'] ) + : array(); + $wrapper_attributes = get_block_wrapper_attributes( $extra_attributes ); + + return '
' . term_description() . '
'; +} + +/** + * Registers the `core/term-description` block on the server. + */ +function register_block_core_term_description() { + register_block_type_from_metadata( + __DIR__ . '/term-description', + array( + 'render_callback' => 'render_block_core_term_description', + ) + ); +} +add_action( 'init', 'register_block_core_term_description' ); diff --git a/packages/e2e-tests/fixtures/blocks/core__term-description.html b/packages/e2e-tests/fixtures/blocks/core__term-description.html new file mode 100644 index 00000000000000..63bb38e7fbe3b4 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__term-description.html @@ -0,0 +1 @@ + diff --git a/packages/e2e-tests/fixtures/blocks/core__term-description.json b/packages/e2e-tests/fixtures/blocks/core__term-description.json new file mode 100644 index 00000000000000..4148e19d752424 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__term-description.json @@ -0,0 +1,12 @@ +[ + { + "clientId": "_clientId_0", + "name": "core/term-description", + "isValid": true, + "attributes": { + "align": "full" + }, + "innerBlocks": [], + "originalContent": "" + } +] diff --git a/packages/e2e-tests/fixtures/blocks/core__term-description.parsed.json b/packages/e2e-tests/fixtures/blocks/core__term-description.parsed.json new file mode 100644 index 00000000000000..30e6c5778a52d4 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__term-description.parsed.json @@ -0,0 +1,20 @@ +[ + { + "blockName": "core/term-description", + "attrs": { + "align": "full" + }, + "innerBlocks": [], + "innerHTML": "", + "innerContent": [] + }, + { + "blockName": null, + "attrs": {}, + "innerBlocks": [], + "innerHTML": "\n", + "innerContent": [ + "\n" + ] + } +] diff --git a/packages/e2e-tests/fixtures/blocks/core__term-description.serialized.html b/packages/e2e-tests/fixtures/blocks/core__term-description.serialized.html new file mode 100644 index 00000000000000..63bb38e7fbe3b4 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__term-description.serialized.html @@ -0,0 +1 @@ + diff --git a/packages/icons/src/index.js b/packages/icons/src/index.js index 3a6457d6b9de63..bbcd6856943ae5 100644 --- a/packages/icons/src/index.js +++ b/packages/icons/src/index.js @@ -189,6 +189,7 @@ export { default as tableRowBefore } from './library/table-row-before'; export { default as tableRowDelete } from './library/table-row-delete'; export { default as table } from './library/table'; export { default as tag } from './library/tag'; +export { default as termDescription } from './library/term-description'; export { default as footer } from './library/footer'; export { default as header } from './library/header'; export { default as sidebar } from './library/sidebar'; diff --git a/packages/icons/src/library/term-description.js b/packages/icons/src/library/term-description.js new file mode 100644 index 00000000000000..5c3efead4ca0c3 --- /dev/null +++ b/packages/icons/src/library/term-description.js @@ -0,0 +1,20 @@ +/** + * WordPress dependencies + */ +import { SVG, Path } from '@wordpress/primitives'; + +const tag = ( + + + + +); + +export default tag;