Skip to content

Commit

Permalink
Convert all remaining dynamic blocks to use metadata format
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Mar 5, 2019
1 parent 7519ab6 commit 33a6265
Show file tree
Hide file tree
Showing 20 changed files with 221 additions and 310 deletions.
13 changes: 1 addition & 12 deletions packages/block-library/src/archives/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ import { __ } from '@wordpress/i18n';
*/
import {
InspectorControls,
BlockAlignmentToolbar,
BlockControls,
ServerSideRender,
} from '@wordpress/editor';

export default function ArchivesEdit( { attributes, setAttributes } ) {
const { align, showPostCounts, displayAsDropdown } = attributes;
const { showPostCounts, displayAsDropdown } = attributes;

return (
<Fragment>
Expand All @@ -38,15 +36,6 @@ export default function ArchivesEdit( { attributes, setAttributes } ) {
/>
</PanelBody>
</InspectorControls>
<BlockControls>
<BlockAlignmentToolbar
value={ align }
onChange={ ( nextAlign ) => {
setAttributes( { align: nextAlign } );
} }
controls={ [ 'left', 'center', 'right' ] }
/>
</BlockControls>
<Disabled>
<ServerSideRender block="core/archives" attributes={ attributes } />
</Disabled>
Expand Down
6 changes: 6 additions & 0 deletions packages/block-library/src/categories/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
},
"description": "Display a list of all categories.",
"attributes": {
"align": {
"type": "string"
},
"className": {
"type": "string"
},
"displayAsDropdown": {
"type": "boolean",
"default": false
Expand Down
41 changes: 41 additions & 0 deletions packages/block-library/src/latest-comments/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "core/latest-comments",
"title": "Latest Comments",
"category": "widgets",
"icon": {
"src": "./icon.js"
},
"description": "Display a list of your most recent comments.",
"keywords": [ "recent comments" ],
"attributes": {
"align": {
"type": "string"
},
"className": {
"type": "string"
},
"commentsToShow": {
"type": "number",
"default": 5,
"minimum": 1,
"maximum": 100
},
"displayAvatar": {
"type": "boolean",
"default": true
},
"displayDate": {
"type": "boolean",
"default": true
},
"displayExcerpt": {
"type": "boolean",
"default": true
}
},
"edit": "./edit.js",
"supports": {
"align": true,
"html": false
}
}
13 changes: 0 additions & 13 deletions packages/block-library/src/latest-comments/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import {
import { __ } from '@wordpress/i18n';
import {
InspectorControls,
BlockAlignmentToolbar,
BlockControls,
ServerSideRender,
} from '@wordpress/editor';

Expand Down Expand Up @@ -53,17 +51,12 @@ class LatestComments extends Component {
};
}

setAlignment( align ) {
this.props.setAttributes( { align } );
}

setCommentsToShow( commentsToShow ) {
this.props.setAttributes( { commentsToShow } );
}

render() {
const {
align,
commentsToShow,
displayAvatar,
displayDate,
Expand All @@ -72,12 +65,6 @@ class LatestComments extends Component {

return (
<Fragment>
<BlockControls>
<BlockAlignmentToolbar
value={ align }
onChange={ this.setAlignment }
/>
</BlockControls>
<InspectorControls>
<PanelBody title={ __( 'Latest Comments Settings' ) }>
<ToggleControl
Expand Down
8 changes: 8 additions & 0 deletions packages/block-library/src/latest-comments/icon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* WordPress dependencies
*/
import { G, Path, SVG } from '@wordpress/components';

export default (
<SVG viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><Path fill="none" d="M0 0h24v24H0V0z" /><G><Path d="M21.99 4c0-1.1-.89-2-1.99-2H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h14l4 4-.01-18zM20 4v13.17L18.83 16H4V4h16zM6 12h12v2H6zm0-3h12v2H6zm0-3h12v2H6z" /></G></SVG>
);
44 changes: 0 additions & 44 deletions packages/block-library/src/latest-comments/index.js

This file was deleted.

46 changes: 13 additions & 33 deletions packages/block-library/src/latest-comments/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,36 +150,16 @@ function render_block_core_latest_comments( $attributes = array() ) {
return $block_content;
}

register_block_type(
'core/latest-comments',
array(
'attributes' => array(
'className' => array(
'type' => 'string',
),
'commentsToShow' => array(
'type' => 'number',
'default' => 5,
'minimum' => 1,
'maximum' => 100,
),
'displayAvatar' => array(
'type' => 'boolean',
'default' => true,
),
'displayDate' => array(
'type' => 'boolean',
'default' => true,
),
'displayExcerpt' => array(
'type' => 'boolean',
'default' => true,
),
'align' => array(
'type' => 'string',
'enum' => array( 'center', 'left', 'right', 'wide', 'full', '' ),
),
),
'render_callback' => 'render_block_core_latest_comments',
)
);
/**
* Registers the `core/latest-comments` block on server.
*/
function register_block_core_latest_comments() {
register_block_type_from_metadata(
dirname( __FILE__ ),
array(
'render_callback' => 'render_block_core_latest_comments',
)
);
}

add_action( 'init', 'register_block_core_latest_comments' );
50 changes: 50 additions & 0 deletions packages/block-library/src/latest-posts/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "core/latest-posts",
"title": "Latest Posts",
"category": "widgets",
"icon": {
"src": "./icon.js"
},
"description": "Display a list of your most recent posts.",
"keywords": [ "recent posts" ],
"attributes": {
"align": {
"type": "string"
},
"className": {
"type": "string"
},
"categories": {
"type": "string"
},
"postsToShow": {
"type": "number",
"default": 5
},
"displayPostDate": {
"type": "boolean",
"default": false
},
"postLayout": {
"type": "string",
"default": "list"
},
"columns": {
"type": "number",
"default": 3
},
"order": {
"type": "string",
"default": "desc"
},
"orderBy": {
"type": "string",
"default": "date"
}
},
"edit": "./edit.js",
"supports": {
"align": true,
"html": false
}
}
9 changes: 1 addition & 8 deletions packages/block-library/src/latest-posts/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { __ } from '@wordpress/i18n';
import { dateI18n, format, __experimentalGetSettings } from '@wordpress/date';
import {
InspectorControls,
BlockAlignmentToolbar,
BlockControls,
} from '@wordpress/editor';
import { withSelect } from '@wordpress/data';
Expand Down Expand Up @@ -82,7 +81,7 @@ class LatestPostsEdit extends Component {
render() {
const { attributes, setAttributes, latestPosts } = this.props;
const { categoriesList } = this.state;
const { displayPostDate, align, postLayout, columns, order, orderBy, categories, postsToShow } = attributes;
const { displayPostDate, postLayout, columns, order, orderBy, categories, postsToShow } = attributes;

const inspectorControls = (
<InspectorControls>
Expand Down Expand Up @@ -159,12 +158,6 @@ class LatestPostsEdit extends Component {
<Fragment>
{ inspectorControls }
<BlockControls>
<BlockAlignmentToolbar
value={ align }
onChange={ ( nextAlign ) => {
setAttributes( { align: nextAlign } );
} }
/>
<Toolbar controls={ layoutControls } />
</BlockControls>
<ul
Expand Down
8 changes: 8 additions & 0 deletions packages/block-library/src/latest-posts/icon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* WordPress dependencies
*/
import { Path, Rect, SVG } from '@wordpress/components';

export default (
<SVG viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><Path d="M0,0h24v24H0V0z" fill="none" /><Rect x="11" y="7" width="6" height="2" /><Rect x="11" y="11" width="6" height="2" /><Rect x="11" y="15" width="6" height="2" /><Rect x="7" y="7" width="2" height="2" /><Rect x="7" y="11" width="2" height="2" /><Rect x="7" y="15" width="2" height="2" /><Path d="M20.1,3H3.9C3.4,3,3,3.4,3,3.9v16.2C3,20.5,3.4,21,3.9,21h16.2c0.4,0,0.9-0.5,0.9-0.9V3.9C21,3.4,20.5,3,20.1,3z M19,19H5V5h14V19z" /></SVG>
);
41 changes: 0 additions & 41 deletions packages/block-library/src/latest-posts/index.js

This file was deleted.

Loading

0 comments on commit 33a6265

Please sign in to comment.