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

Add term-description block #29613

Merged
merged 17 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
)
),
),
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -240,6 +241,7 @@ export const __experimentalRegisterExperimentalCoreBlocks =
postHierarchicalTerms,
postTags,
postNavigationLink,
termDescription,
]
: [] ),
].forEach( registerBlock );
Expand Down
20 changes: 20 additions & 0 deletions packages/block-library/src/term-description/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"apiVersion": 2,
"name": "core/term-description",
"category": "design",
"attributes": {
"textAlign": {
aristath marked this conversation as resolved.
Show resolved Hide resolved
"type": "string"
}
},
"supports": {
"align": [ "wide", "full" ],
"html": false,
"fontSize": true,
"lineHeight": true,
"color": {
"link": true
}
},
"editorStyle": "wp-block-term-description-editor"
}
45 changes: 45 additions & 0 deletions packages/block-library/src/term-description/edit.js
Original file line number Diff line number Diff line change
@@ -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 (
<>
<BlockControls>
<AlignmentToolbar
value={ textAlign }
onChange={ ( nextAlign ) => {
setAttributes( { textAlign: nextAlign } );
} }
/>
</BlockControls>
<div { ...blockProps }>
<div className="wp-block-term-description__placeholder">
<span>{ __( 'Term description.' ) }</span>
</div>
</div>
</>
);
}
4 changes: 4 additions & 0 deletions packages/block-library/src/term-description/editor.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.wp-block-term-description__placeholder {
aristath marked this conversation as resolved.
Show resolved Hide resolved
padding: 1em 0;
aristath marked this conversation as resolved.
Show resolved Hide resolved
border: 1px dashed;
}
23 changes: 23 additions & 0 deletions packages/block-library/src/term-description/index.js
Original file line number Diff line number Diff line change
@@ -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' ),
aristath marked this conversation as resolved.
Show resolved Hide resolved
description: __(
'Display the description of categories, tags and custom taxonomies when viewing an archive.'
),
icon,
edit,
};
41 changes: 41 additions & 0 deletions packages/block-library/src/term-description/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Server-side rendering of the `core/term-description` block.
*
* @package WordPress
*/

/**
* Renders the `core/term-description` 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 filtered post content of the current post.
*/
function render_block_core_term_description( $attributes, $content, $block ) {

if ( ! is_category() && ! is_tag() && ! is_tax() ) {
return '';
}

$extra_attributes = ( isset( $attributes['textAlign'] ) )
? array( 'class' => 'has-text-align-' . $attributes['textAlign'] )
: array();
$wrapper_attributes = get_block_wrapper_attributes( $extra_attributes );

return '<div ' . $wrapper_attributes . '>' . term_description() . '</div>';
ntsekouras marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* 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' );
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- wp:term-description {"align":"full"} /-->
12 changes: 12 additions & 0 deletions packages/e2e-tests/fixtures/blocks/core__term-description.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"clientId": "_clientId_0",
"name": "core/term-description",
"isValid": true,
"attributes": {
"align": "full"
},
"innerBlocks": [],
"originalContent": ""
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"blockName": "core/term-description",
"attrs": {
"align": "full"
},
"innerBlocks": [],
"innerHTML": "",
"innerContent": []
},
{
"blockName": null,
"attrs": {},
"innerBlocks": [],
"innerHTML": "\n",
"innerContent": [
"\n"
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- wp:term-description {"align":"full"} /-->
1 change: 1 addition & 0 deletions packages/icons/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
20 changes: 20 additions & 0 deletions packages/icons/src/library/term-description.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* WordPress dependencies
*/
import { SVG, Path } from '@wordpress/primitives';

const tag = (
<SVG xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<Path
stroke="#1E1E1E"
strokeWidth="1.5"
d="M9 19.25h6M4 19.25h4M12 15.25h8M4 15.25h7"
/>
<Path
d="M8.994 10.103H6.08L5.417 12H4l2.846-8h1.383l2.845 8H9.657l-.663-1.897zm-.457-1.28l-.994-2.857-1.006 2.857h2z"
fill="#1E1E1E"
/>
</SVG>
);

export default tag;