From e5a56254309cd513d80f9892f34c585c28fd7e7a Mon Sep 17 00:00:00 2001
From: Javier Villanueva
Date: Sat, 10 Feb 2018 20:01:39 +0000
Subject: [PATCH 01/16] Add tag cloud block
---
packages/block-library/src/index.js | 8 +-
packages/block-library/src/tag-cloud/edit.js | 123 ++++++++++++++++++
.../block-library/src/tag-cloud/editor.scss | 13 ++
packages/block-library/src/tag-cloud/index.js | 33 +++++
.../block-library/src/tag-cloud/index.php | 58 +++++++++
.../fixtures/core__tag-cloud.html | 1 +
.../fixtures/core__tag-cloud.json | 14 ++
.../fixtures/core__tag-cloud.parsed.json | 10 ++
.../fixtures/core__tag-cloud.serialized.html | 1 +
.../core__tag-cloud__showTagCounts.html | 1 +
.../core__tag-cloud__showTagCounts.json | 14 ++
...core__tag-cloud__showTagCounts.parsed.json | 11 ++
...__tag-cloud__showTagCounts.serialized.html | 1 +
.../full-content/server-registered.json | 2 +-
14 files changed, 284 insertions(+), 6 deletions(-)
create mode 100644 packages/block-library/src/tag-cloud/edit.js
create mode 100644 packages/block-library/src/tag-cloud/editor.scss
create mode 100644 packages/block-library/src/tag-cloud/index.js
create mode 100644 packages/block-library/src/tag-cloud/index.php
create mode 100644 test/integration/full-content/fixtures/core__tag-cloud.html
create mode 100644 test/integration/full-content/fixtures/core__tag-cloud.json
create mode 100644 test/integration/full-content/fixtures/core__tag-cloud.parsed.json
create mode 100644 test/integration/full-content/fixtures/core__tag-cloud.serialized.html
create mode 100644 test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.html
create mode 100644 test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.json
create mode 100644 test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.parsed.json
create mode 100644 test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.serialized.html
diff --git a/packages/block-library/src/index.js b/packages/block-library/src/index.js
index ecb354f8c373e5..0a956eaa03bcd8 100644
--- a/packages/block-library/src/index.js
+++ b/packages/block-library/src/index.js
@@ -47,6 +47,7 @@ import * as template from './template';
import * as textColumns from './text-columns';
import * as verse from './verse';
import * as video from './video';
+import * as tagCloud from './tag-cloud';
import * as classic from './classic';
@@ -94,11 +95,8 @@ export const registerCoreBlocks = () => {
textColumns,
verse,
video,
- ].forEach( ( block ) => {
- if ( ! block ) {
- return;
- }
- const { name, settings } = block;
+ tagCloud,
+ ].forEach( ( { name, settings } ) => {
registerBlockType( name, settings );
} );
diff --git a/packages/block-library/src/tag-cloud/edit.js b/packages/block-library/src/tag-cloud/edit.js
new file mode 100644
index 00000000000000..e1eb2e59262ad8
--- /dev/null
+++ b/packages/block-library/src/tag-cloud/edit.js
@@ -0,0 +1,123 @@
+/**
+ * External dependencies
+ */
+import { map, filter } from 'lodash';
+
+/**
+ * WordPress dependencies
+ */
+import { Component, Fragment } from '@wordpress/element';
+import {
+ PanelBody,
+ Placeholder,
+ ToggleControl,
+ SelectControl,
+ ServerSideRender,
+} from '@wordpress/components';
+import { withSelect } from '@wordpress/data';
+import { __ } from '@wordpress/i18n';
+
+/**
+ * Internal dependencies
+ */
+import { InspectorControls } from '@wordpress/editor';
+
+class TagCloudEdit extends Component {
+ constructor() {
+ super( ...arguments );
+
+ this.setTaxonomy = this.setTaxonomy.bind( this );
+ this.toggleShowTagCounts = this.toggleShowTagCounts.bind( this );
+ }
+
+ getTaxonomies() {
+ const taxonomies = filter( this.props.taxonomies, 'show_cloud' );
+
+ return map( taxonomies, ( taxonomy ) => {
+ return {
+ value: taxonomy.slug,
+ label: taxonomy.name,
+ };
+ } );
+ }
+
+ setTaxonomy( taxonomy ) {
+ const { setAttributes } = this.props;
+
+ setAttributes( { taxonomy } );
+ }
+
+ toggleShowTagCounts() {
+ const { attributes, setAttributes } = this.props;
+ const { showTagCounts } = attributes;
+
+ setAttributes( { showTagCounts: ! showTagCounts } );
+ }
+
+ render() {
+ const { attributes } = this.props;
+ const { taxonomy, showTagCounts } = attributes;
+ const taxonomies = this.getTaxonomies();
+ const options = [
+ {
+ label: __( '- Select -' ),
+ value: '',
+ },
+ ...taxonomies,
+ ];
+
+ const inspectorControls = (
+
+
+
+
+
+
+ );
+
+ if ( ! taxonomy ) {
+ return (
+
+ { inspectorControls }
+
+
+
+
+ );
+ }
+
+ return (
+
+ { inspectorControls }
+
+
+ );
+ }
+}
+
+export default withSelect( ( select ) => {
+ return {
+ taxonomies: select( 'core' ).getTaxonomies(),
+ };
+} )( TagCloudEdit );
diff --git a/packages/block-library/src/tag-cloud/editor.scss b/packages/block-library/src/tag-cloud/editor.scss
new file mode 100644
index 00000000000000..ae00bc16dd8349
--- /dev/null
+++ b/packages/block-library/src/tag-cloud/editor.scss
@@ -0,0 +1,13 @@
+.gutenberg .wp-block-tag-cloud {
+ a {
+ display: inline-block;
+ margin-right: 5px;
+ }
+
+ span {
+ display: inline-block;
+ margin-left: 5px;
+ color: $dark-gray-100;
+ text-decoration: none;
+ }
+}
diff --git a/packages/block-library/src/tag-cloud/index.js b/packages/block-library/src/tag-cloud/index.js
new file mode 100644
index 00000000000000..628668c23126af
--- /dev/null
+++ b/packages/block-library/src/tag-cloud/index.js
@@ -0,0 +1,33 @@
+/**
+ * WordPress dependencies
+ */
+import { __ } from '@wordpress/i18n';
+
+/**
+ * Internal dependencies
+ */
+import './editor.scss';
+import edit from './edit';
+
+export const name = 'core/tag-cloud';
+
+export const settings = {
+ title: __( 'Tag Cloud' ),
+
+ description: __( 'A cloud of your most used tags.' ),
+
+ icon: 'tag',
+
+ category: 'widgets',
+
+ supports: {
+ html: false,
+ align: true,
+ },
+
+ edit,
+
+ save() {
+ return null;
+ },
+};
diff --git a/packages/block-library/src/tag-cloud/index.php b/packages/block-library/src/tag-cloud/index.php
new file mode 100644
index 00000000000000..dabe4d5189d121
--- /dev/null
+++ b/packages/block-library/src/tag-cloud/index.php
@@ -0,0 +1,58 @@
+%2$s
';
+
+ $args = array(
+ 'echo' => false,
+ 'taxonomy' => $attributes['taxonomy'],
+ 'show_count' => ! empty( $attributes['showTagCounts'] ),
+ );
+
+ $tag_cloud = wp_tag_cloud( $args );
+
+ $block_content = sprintf(
+ $wrapper_markup,
+ esc_attr( $class ),
+ $tag_cloud
+ );
+
+ return $block_content;
+}
+
+/**
+ * Registers the `core/tag-cloud` block on server.
+ */
+function register_block_core_tag_cloud() {
+ register_block_type( 'core/tag-cloud', array(
+ 'attributes' => array(
+ 'taxonomy' => array(
+ 'type' => 'string',
+ ),
+ 'showTagCounts' => array(
+ 'type' => 'boolean',
+ 'default' => false,
+ ),
+ 'align' => array(
+ 'type' => 'string',
+ 'default' => 'center',
+ ),
+ ),
+ 'render_callback' => 'render_block_core_tag_cloud',
+ ) );
+}
+
+add_action( 'init', 'register_block_core_tag_cloud' );
diff --git a/test/integration/full-content/fixtures/core__tag-cloud.html b/test/integration/full-content/fixtures/core__tag-cloud.html
new file mode 100644
index 00000000000000..05ef749fc0b354
--- /dev/null
+++ b/test/integration/full-content/fixtures/core__tag-cloud.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/test/integration/full-content/fixtures/core__tag-cloud.json b/test/integration/full-content/fixtures/core__tag-cloud.json
new file mode 100644
index 00000000000000..a75b9e2154778a
--- /dev/null
+++ b/test/integration/full-content/fixtures/core__tag-cloud.json
@@ -0,0 +1,14 @@
+[
+ {
+ "clientId": "_clientId_0",
+ "name": "core/tag-cloud",
+ "isValid": true,
+ "attributes": {
+ "taxonomy": "category",
+ "showTagCounts": false,
+ "align": "center"
+ },
+ "innerBlocks": [],
+ "originalContent": ""
+ }
+]
diff --git a/test/integration/full-content/fixtures/core__tag-cloud.parsed.json b/test/integration/full-content/fixtures/core__tag-cloud.parsed.json
new file mode 100644
index 00000000000000..e310f66541798f
--- /dev/null
+++ b/test/integration/full-content/fixtures/core__tag-cloud.parsed.json
@@ -0,0 +1,10 @@
+[
+ {
+ "blockName": "core/tag-cloud",
+ "attrs": {
+ "taxonomy": "category"
+ },
+ "innerBlocks": [],
+ "innerHTML": ""
+ }
+]
diff --git a/test/integration/full-content/fixtures/core__tag-cloud.serialized.html b/test/integration/full-content/fixtures/core__tag-cloud.serialized.html
new file mode 100644
index 00000000000000..d342963579e299
--- /dev/null
+++ b/test/integration/full-content/fixtures/core__tag-cloud.serialized.html
@@ -0,0 +1 @@
+
diff --git a/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.html b/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.html
new file mode 100644
index 00000000000000..3f22f21fc6cfe9
--- /dev/null
+++ b/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.json b/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.json
new file mode 100644
index 00000000000000..cc73b1ec0e009f
--- /dev/null
+++ b/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.json
@@ -0,0 +1,14 @@
+[
+ {
+ "clientId": "_clientId_0",
+ "name": "core/tag-cloud",
+ "isValid": true,
+ "attributes": {
+ "taxonomy": "category",
+ "showTagCounts": true,
+ "align": "center"
+ },
+ "innerBlocks": [],
+ "originalContent": ""
+ }
+]
diff --git a/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.parsed.json b/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.parsed.json
new file mode 100644
index 00000000000000..96d168f161eb8b
--- /dev/null
+++ b/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.parsed.json
@@ -0,0 +1,11 @@
+[
+ {
+ "blockName": "core/tag-cloud",
+ "attrs": {
+ "taxonomy": "category",
+ "showTagCounts": true
+ },
+ "innerBlocks": [],
+ "innerHTML": ""
+ }
+]
diff --git a/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.serialized.html b/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.serialized.html
new file mode 100644
index 00000000000000..9711e8c6ad6c0b
--- /dev/null
+++ b/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.serialized.html
@@ -0,0 +1 @@
+
diff --git a/test/integration/full-content/server-registered.json b/test/integration/full-content/server-registered.json
index 65eb48d6d53f28..257a60f7908351 100644
--- a/test/integration/full-content/server-registered.json
+++ b/test/integration/full-content/server-registered.json
@@ -1 +1 @@
-{"core\/block":{"attributes":{"ref":{"type":"number"}}},"core\/latest-comments":{"attributes":{"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},"align":{"type":"string","enum":["center","left","right","wide","full",""]}}},"core\/archives":{"attributes":{"align":{"type":"string"},"className":{"type":"string"},"displayAsDropdown":{"type":"boolean","default":false},"showPostCounts":{"type":"boolean","default":false}}},"core\/latest-posts":{"attributes":{"categories":{"type":"string"},"className":{"type":"string"},"postsToShow":{"type":"number","default":5},"displayPostDate":{"type":"boolean","default":false},"postLayout":{"type":"string","default":"list"},"columns":{"type":"number","default":3},"align":{"type":"string"},"order":{"type":"string","default":"desc"},"orderBy":{"type":"string","default":"date"}}}}
\ No newline at end of file
+{"core\/block":{"attributes":{"ref":{"type":"number"}}},"core\/latest-comments":{"attributes":{"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},"align":{"type":"string","enum":["center","left","right","wide","full",""]}}},"core\/archives":{"attributes":{"align":{"type":"string"},"className":{"type":"string"},"displayAsDropdown":{"type":"boolean","default":false},"showPostCounts":{"type":"boolean","default":false}}},"core\/latest-posts":{"attributes":{"categories":{"type":"string"},"className":{"type":"string"},"postsToShow":{"type":"number","default":5},"displayPostDate":{"type":"boolean","default":false},"postLayout":{"type":"string","default":"list"},"columns":{"type":"number","default":3},"align":{"type":"string"},"order":{"type":"string","default":"desc"},"orderBy":{"type":"string","default":"date"}}},"core\/tag-cloud":{"attributes":{"taxonomy":{"type":"string"},"showTagCounts":{"type":"boolean","default":false},"align":{"type":"string","default":"center"}}}}
\ No newline at end of file
From 764b18111d756295ecdc94bf56a0e97f0b521d0a Mon Sep 17 00:00:00 2001
From: Javier Villanueva
Date: Tue, 21 Aug 2018 13:13:43 +0100
Subject: [PATCH 02/16] Fix phpcs format issues
---
.../block-library/src/tag-cloud/index.php | 33 ++++++++++---------
1 file changed, 18 insertions(+), 15 deletions(-)
diff --git a/packages/block-library/src/tag-cloud/index.php b/packages/block-library/src/tag-cloud/index.php
index dabe4d5189d121..3d0ded1a3f3865 100644
--- a/packages/block-library/src/tag-cloud/index.php
+++ b/packages/block-library/src/tag-cloud/index.php
@@ -37,22 +37,25 @@ function render_block_core_tag_cloud( $attributes ) {
* Registers the `core/tag-cloud` block on server.
*/
function register_block_core_tag_cloud() {
- register_block_type( 'core/tag-cloud', array(
- 'attributes' => array(
- 'taxonomy' => array(
- 'type' => 'string',
+ register_block_type(
+ 'core/tag-cloud',
+ array(
+ 'attributes' => array(
+ 'taxonomy' => array(
+ 'type' => 'string',
+ ),
+ 'showTagCounts' => array(
+ 'type' => 'boolean',
+ 'default' => false,
+ ),
+ 'align' => array(
+ 'type' => 'string',
+ 'default' => 'center',
+ ),
),
- 'showTagCounts' => array(
- 'type' => 'boolean',
- 'default' => false,
- ),
- 'align' => array(
- 'type' => 'string',
- 'default' => 'center',
- ),
- ),
- 'render_callback' => 'render_block_core_tag_cloud',
- ) );
+ 'render_callback' => 'render_block_core_tag_cloud',
+ )
+ );
}
add_action( 'init', 'register_block_core_tag_cloud' );
From 2ebaffd146f14b7aea0ed1330f296fc40eeae635 Mon Sep 17 00:00:00 2001
From: Javier Villanueva
Date: Tue, 9 Oct 2018 12:55:35 +0100
Subject: [PATCH 03/16] Move styles import to main editor.scss file
---
packages/block-library/src/editor.scss | 1 +
packages/block-library/src/tag-cloud/index.js | 1 -
2 files changed, 1 insertion(+), 1 deletion(-)
diff --git a/packages/block-library/src/editor.scss b/packages/block-library/src/editor.scss
index eb2dea826189bd..41d0c539eddc3b 100644
--- a/packages/block-library/src/editor.scss
+++ b/packages/block-library/src/editor.scss
@@ -29,3 +29,4 @@
@import "./text-columns/editor.scss";
@import "./verse/editor.scss";
@import "./video/editor.scss";
+@import "./tag-cloud/editor.scss";
diff --git a/packages/block-library/src/tag-cloud/index.js b/packages/block-library/src/tag-cloud/index.js
index 628668c23126af..cc785fdb3167a4 100644
--- a/packages/block-library/src/tag-cloud/index.js
+++ b/packages/block-library/src/tag-cloud/index.js
@@ -6,7 +6,6 @@ import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
-import './editor.scss';
import edit from './edit';
export const name = 'core/tag-cloud';
From 7ffa1625c8059419b9aaebb876800855e03cd7ea Mon Sep 17 00:00:00 2001
From: Javier Villanueva
Date: Sat, 15 Dec 2018 20:35:32 +0000
Subject: [PATCH 04/16] Include server side script on load
---
lib/load.php | 3 +++
packages/block-library/src/tag-cloud/edit.js | 2 +-
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/lib/load.php b/lib/load.php
index ee1c973f99568a..da1a0f7092c41b 100644
--- a/lib/load.php
+++ b/lib/load.php
@@ -74,3 +74,6 @@
if ( ! function_exists( 'render_block_core_shortcode' ) ) {
require dirname( __FILE__ ) . '/../packages/block-library/src/shortcode/index.php';
}
+if ( ! function_exists( 'render_block_core_tag_cloud' ) ) {
+ require dirname( __FILE__ ) . '/../packages/block-library/src/tag-cloud/index.php';
+}
diff --git a/packages/block-library/src/tag-cloud/edit.js b/packages/block-library/src/tag-cloud/edit.js
index e1eb2e59262ad8..f9765a248a0fd6 100644
--- a/packages/block-library/src/tag-cloud/edit.js
+++ b/packages/block-library/src/tag-cloud/edit.js
@@ -118,6 +118,6 @@ class TagCloudEdit extends Component {
export default withSelect( ( select ) => {
return {
- taxonomies: select( 'core' ).getTaxonomies(),
+ taxonomies: select( 'core' ).getTaxonomies( { per_page: -1 } ),
};
} )( TagCloudEdit );
From 126cf685d00d05f5c528d24f27722c7b827e73a7 Mon Sep 17 00:00:00 2001
From: Javier Villanueva
Date: Sat, 15 Dec 2018 22:32:20 +0000
Subject: [PATCH 05/16] Add missing fixtures
---
.../full-content/fixtures/core__tag-cloud.parsed.json | 3 ++-
.../fixtures/core__tag-cloud__showTagCounts.parsed.json | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/test/integration/full-content/fixtures/core__tag-cloud.parsed.json b/test/integration/full-content/fixtures/core__tag-cloud.parsed.json
index e310f66541798f..cb601766c2b8e1 100644
--- a/test/integration/full-content/fixtures/core__tag-cloud.parsed.json
+++ b/test/integration/full-content/fixtures/core__tag-cloud.parsed.json
@@ -5,6 +5,7 @@
"taxonomy": "category"
},
"innerBlocks": [],
- "innerHTML": ""
+ "innerHTML": "",
+ "innerContent": []
}
]
diff --git a/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.parsed.json b/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.parsed.json
index 96d168f161eb8b..d9f82c35762450 100644
--- a/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.parsed.json
+++ b/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.parsed.json
@@ -6,6 +6,7 @@
"showTagCounts": true
},
"innerBlocks": [],
- "innerHTML": ""
+ "innerHTML": "",
+ "innerContent": []
}
]
From e692611d23e69478cc6c1c81ff6d122b654d5fa7 Mon Sep 17 00:00:00 2001
From: Javier Villanueva
Date: Sat, 10 Feb 2018 20:01:39 +0000
Subject: [PATCH 06/16] Add tag cloud block
---
packages/block-library/src/index.js | 8 +-
packages/block-library/src/tag-cloud/edit.js | 123 ++++++++++++++++++
.../block-library/src/tag-cloud/editor.scss | 13 ++
packages/block-library/src/tag-cloud/index.js | 33 +++++
.../block-library/src/tag-cloud/index.php | 58 +++++++++
.../fixtures/core__tag-cloud.html | 1 +
.../fixtures/core__tag-cloud.json | 14 ++
.../fixtures/core__tag-cloud.parsed.json | 10 ++
.../fixtures/core__tag-cloud.serialized.html | 1 +
.../core__tag-cloud__showTagCounts.html | 1 +
.../core__tag-cloud__showTagCounts.json | 14 ++
...core__tag-cloud__showTagCounts.parsed.json | 11 ++
...__tag-cloud__showTagCounts.serialized.html | 1 +
.../full-content/server-registered.json | 2 +-
14 files changed, 284 insertions(+), 6 deletions(-)
create mode 100644 packages/block-library/src/tag-cloud/edit.js
create mode 100644 packages/block-library/src/tag-cloud/editor.scss
create mode 100644 packages/block-library/src/tag-cloud/index.js
create mode 100644 packages/block-library/src/tag-cloud/index.php
create mode 100644 test/integration/full-content/fixtures/core__tag-cloud.html
create mode 100644 test/integration/full-content/fixtures/core__tag-cloud.json
create mode 100644 test/integration/full-content/fixtures/core__tag-cloud.parsed.json
create mode 100644 test/integration/full-content/fixtures/core__tag-cloud.serialized.html
create mode 100644 test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.html
create mode 100644 test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.json
create mode 100644 test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.parsed.json
create mode 100644 test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.serialized.html
diff --git a/packages/block-library/src/index.js b/packages/block-library/src/index.js
index ecb354f8c373e5..0a956eaa03bcd8 100644
--- a/packages/block-library/src/index.js
+++ b/packages/block-library/src/index.js
@@ -47,6 +47,7 @@ import * as template from './template';
import * as textColumns from './text-columns';
import * as verse from './verse';
import * as video from './video';
+import * as tagCloud from './tag-cloud';
import * as classic from './classic';
@@ -94,11 +95,8 @@ export const registerCoreBlocks = () => {
textColumns,
verse,
video,
- ].forEach( ( block ) => {
- if ( ! block ) {
- return;
- }
- const { name, settings } = block;
+ tagCloud,
+ ].forEach( ( { name, settings } ) => {
registerBlockType( name, settings );
} );
diff --git a/packages/block-library/src/tag-cloud/edit.js b/packages/block-library/src/tag-cloud/edit.js
new file mode 100644
index 00000000000000..e1eb2e59262ad8
--- /dev/null
+++ b/packages/block-library/src/tag-cloud/edit.js
@@ -0,0 +1,123 @@
+/**
+ * External dependencies
+ */
+import { map, filter } from 'lodash';
+
+/**
+ * WordPress dependencies
+ */
+import { Component, Fragment } from '@wordpress/element';
+import {
+ PanelBody,
+ Placeholder,
+ ToggleControl,
+ SelectControl,
+ ServerSideRender,
+} from '@wordpress/components';
+import { withSelect } from '@wordpress/data';
+import { __ } from '@wordpress/i18n';
+
+/**
+ * Internal dependencies
+ */
+import { InspectorControls } from '@wordpress/editor';
+
+class TagCloudEdit extends Component {
+ constructor() {
+ super( ...arguments );
+
+ this.setTaxonomy = this.setTaxonomy.bind( this );
+ this.toggleShowTagCounts = this.toggleShowTagCounts.bind( this );
+ }
+
+ getTaxonomies() {
+ const taxonomies = filter( this.props.taxonomies, 'show_cloud' );
+
+ return map( taxonomies, ( taxonomy ) => {
+ return {
+ value: taxonomy.slug,
+ label: taxonomy.name,
+ };
+ } );
+ }
+
+ setTaxonomy( taxonomy ) {
+ const { setAttributes } = this.props;
+
+ setAttributes( { taxonomy } );
+ }
+
+ toggleShowTagCounts() {
+ const { attributes, setAttributes } = this.props;
+ const { showTagCounts } = attributes;
+
+ setAttributes( { showTagCounts: ! showTagCounts } );
+ }
+
+ render() {
+ const { attributes } = this.props;
+ const { taxonomy, showTagCounts } = attributes;
+ const taxonomies = this.getTaxonomies();
+ const options = [
+ {
+ label: __( '- Select -' ),
+ value: '',
+ },
+ ...taxonomies,
+ ];
+
+ const inspectorControls = (
+
+
+
+
+
+
+ );
+
+ if ( ! taxonomy ) {
+ return (
+
+ { inspectorControls }
+
+
+
+
+ );
+ }
+
+ return (
+
+ { inspectorControls }
+
+
+ );
+ }
+}
+
+export default withSelect( ( select ) => {
+ return {
+ taxonomies: select( 'core' ).getTaxonomies(),
+ };
+} )( TagCloudEdit );
diff --git a/packages/block-library/src/tag-cloud/editor.scss b/packages/block-library/src/tag-cloud/editor.scss
new file mode 100644
index 00000000000000..ae00bc16dd8349
--- /dev/null
+++ b/packages/block-library/src/tag-cloud/editor.scss
@@ -0,0 +1,13 @@
+.gutenberg .wp-block-tag-cloud {
+ a {
+ display: inline-block;
+ margin-right: 5px;
+ }
+
+ span {
+ display: inline-block;
+ margin-left: 5px;
+ color: $dark-gray-100;
+ text-decoration: none;
+ }
+}
diff --git a/packages/block-library/src/tag-cloud/index.js b/packages/block-library/src/tag-cloud/index.js
new file mode 100644
index 00000000000000..628668c23126af
--- /dev/null
+++ b/packages/block-library/src/tag-cloud/index.js
@@ -0,0 +1,33 @@
+/**
+ * WordPress dependencies
+ */
+import { __ } from '@wordpress/i18n';
+
+/**
+ * Internal dependencies
+ */
+import './editor.scss';
+import edit from './edit';
+
+export const name = 'core/tag-cloud';
+
+export const settings = {
+ title: __( 'Tag Cloud' ),
+
+ description: __( 'A cloud of your most used tags.' ),
+
+ icon: 'tag',
+
+ category: 'widgets',
+
+ supports: {
+ html: false,
+ align: true,
+ },
+
+ edit,
+
+ save() {
+ return null;
+ },
+};
diff --git a/packages/block-library/src/tag-cloud/index.php b/packages/block-library/src/tag-cloud/index.php
new file mode 100644
index 00000000000000..dabe4d5189d121
--- /dev/null
+++ b/packages/block-library/src/tag-cloud/index.php
@@ -0,0 +1,58 @@
+%2$s';
+
+ $args = array(
+ 'echo' => false,
+ 'taxonomy' => $attributes['taxonomy'],
+ 'show_count' => ! empty( $attributes['showTagCounts'] ),
+ );
+
+ $tag_cloud = wp_tag_cloud( $args );
+
+ $block_content = sprintf(
+ $wrapper_markup,
+ esc_attr( $class ),
+ $tag_cloud
+ );
+
+ return $block_content;
+}
+
+/**
+ * Registers the `core/tag-cloud` block on server.
+ */
+function register_block_core_tag_cloud() {
+ register_block_type( 'core/tag-cloud', array(
+ 'attributes' => array(
+ 'taxonomy' => array(
+ 'type' => 'string',
+ ),
+ 'showTagCounts' => array(
+ 'type' => 'boolean',
+ 'default' => false,
+ ),
+ 'align' => array(
+ 'type' => 'string',
+ 'default' => 'center',
+ ),
+ ),
+ 'render_callback' => 'render_block_core_tag_cloud',
+ ) );
+}
+
+add_action( 'init', 'register_block_core_tag_cloud' );
diff --git a/test/integration/full-content/fixtures/core__tag-cloud.html b/test/integration/full-content/fixtures/core__tag-cloud.html
new file mode 100644
index 00000000000000..05ef749fc0b354
--- /dev/null
+++ b/test/integration/full-content/fixtures/core__tag-cloud.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/test/integration/full-content/fixtures/core__tag-cloud.json b/test/integration/full-content/fixtures/core__tag-cloud.json
new file mode 100644
index 00000000000000..a75b9e2154778a
--- /dev/null
+++ b/test/integration/full-content/fixtures/core__tag-cloud.json
@@ -0,0 +1,14 @@
+[
+ {
+ "clientId": "_clientId_0",
+ "name": "core/tag-cloud",
+ "isValid": true,
+ "attributes": {
+ "taxonomy": "category",
+ "showTagCounts": false,
+ "align": "center"
+ },
+ "innerBlocks": [],
+ "originalContent": ""
+ }
+]
diff --git a/test/integration/full-content/fixtures/core__tag-cloud.parsed.json b/test/integration/full-content/fixtures/core__tag-cloud.parsed.json
new file mode 100644
index 00000000000000..e310f66541798f
--- /dev/null
+++ b/test/integration/full-content/fixtures/core__tag-cloud.parsed.json
@@ -0,0 +1,10 @@
+[
+ {
+ "blockName": "core/tag-cloud",
+ "attrs": {
+ "taxonomy": "category"
+ },
+ "innerBlocks": [],
+ "innerHTML": ""
+ }
+]
diff --git a/test/integration/full-content/fixtures/core__tag-cloud.serialized.html b/test/integration/full-content/fixtures/core__tag-cloud.serialized.html
new file mode 100644
index 00000000000000..d342963579e299
--- /dev/null
+++ b/test/integration/full-content/fixtures/core__tag-cloud.serialized.html
@@ -0,0 +1 @@
+
diff --git a/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.html b/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.html
new file mode 100644
index 00000000000000..3f22f21fc6cfe9
--- /dev/null
+++ b/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.json b/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.json
new file mode 100644
index 00000000000000..cc73b1ec0e009f
--- /dev/null
+++ b/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.json
@@ -0,0 +1,14 @@
+[
+ {
+ "clientId": "_clientId_0",
+ "name": "core/tag-cloud",
+ "isValid": true,
+ "attributes": {
+ "taxonomy": "category",
+ "showTagCounts": true,
+ "align": "center"
+ },
+ "innerBlocks": [],
+ "originalContent": ""
+ }
+]
diff --git a/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.parsed.json b/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.parsed.json
new file mode 100644
index 00000000000000..96d168f161eb8b
--- /dev/null
+++ b/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.parsed.json
@@ -0,0 +1,11 @@
+[
+ {
+ "blockName": "core/tag-cloud",
+ "attrs": {
+ "taxonomy": "category",
+ "showTagCounts": true
+ },
+ "innerBlocks": [],
+ "innerHTML": ""
+ }
+]
diff --git a/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.serialized.html b/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.serialized.html
new file mode 100644
index 00000000000000..9711e8c6ad6c0b
--- /dev/null
+++ b/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.serialized.html
@@ -0,0 +1 @@
+
diff --git a/test/integration/full-content/server-registered.json b/test/integration/full-content/server-registered.json
index 65eb48d6d53f28..257a60f7908351 100644
--- a/test/integration/full-content/server-registered.json
+++ b/test/integration/full-content/server-registered.json
@@ -1 +1 @@
-{"core\/block":{"attributes":{"ref":{"type":"number"}}},"core\/latest-comments":{"attributes":{"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},"align":{"type":"string","enum":["center","left","right","wide","full",""]}}},"core\/archives":{"attributes":{"align":{"type":"string"},"className":{"type":"string"},"displayAsDropdown":{"type":"boolean","default":false},"showPostCounts":{"type":"boolean","default":false}}},"core\/latest-posts":{"attributes":{"categories":{"type":"string"},"className":{"type":"string"},"postsToShow":{"type":"number","default":5},"displayPostDate":{"type":"boolean","default":false},"postLayout":{"type":"string","default":"list"},"columns":{"type":"number","default":3},"align":{"type":"string"},"order":{"type":"string","default":"desc"},"orderBy":{"type":"string","default":"date"}}}}
\ No newline at end of file
+{"core\/block":{"attributes":{"ref":{"type":"number"}}},"core\/latest-comments":{"attributes":{"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},"align":{"type":"string","enum":["center","left","right","wide","full",""]}}},"core\/archives":{"attributes":{"align":{"type":"string"},"className":{"type":"string"},"displayAsDropdown":{"type":"boolean","default":false},"showPostCounts":{"type":"boolean","default":false}}},"core\/latest-posts":{"attributes":{"categories":{"type":"string"},"className":{"type":"string"},"postsToShow":{"type":"number","default":5},"displayPostDate":{"type":"boolean","default":false},"postLayout":{"type":"string","default":"list"},"columns":{"type":"number","default":3},"align":{"type":"string"},"order":{"type":"string","default":"desc"},"orderBy":{"type":"string","default":"date"}}},"core\/tag-cloud":{"attributes":{"taxonomy":{"type":"string"},"showTagCounts":{"type":"boolean","default":false},"align":{"type":"string","default":"center"}}}}
\ No newline at end of file
From 6f51a1a49afd7c0425fadac2d83a09032113803e Mon Sep 17 00:00:00 2001
From: Javier Villanueva
Date: Tue, 21 Aug 2018 13:13:43 +0100
Subject: [PATCH 07/16] Fix phpcs format issues
---
.../block-library/src/tag-cloud/index.php | 33 ++++++++++---------
1 file changed, 18 insertions(+), 15 deletions(-)
diff --git a/packages/block-library/src/tag-cloud/index.php b/packages/block-library/src/tag-cloud/index.php
index dabe4d5189d121..3d0ded1a3f3865 100644
--- a/packages/block-library/src/tag-cloud/index.php
+++ b/packages/block-library/src/tag-cloud/index.php
@@ -37,22 +37,25 @@ function render_block_core_tag_cloud( $attributes ) {
* Registers the `core/tag-cloud` block on server.
*/
function register_block_core_tag_cloud() {
- register_block_type( 'core/tag-cloud', array(
- 'attributes' => array(
- 'taxonomy' => array(
- 'type' => 'string',
+ register_block_type(
+ 'core/tag-cloud',
+ array(
+ 'attributes' => array(
+ 'taxonomy' => array(
+ 'type' => 'string',
+ ),
+ 'showTagCounts' => array(
+ 'type' => 'boolean',
+ 'default' => false,
+ ),
+ 'align' => array(
+ 'type' => 'string',
+ 'default' => 'center',
+ ),
),
- 'showTagCounts' => array(
- 'type' => 'boolean',
- 'default' => false,
- ),
- 'align' => array(
- 'type' => 'string',
- 'default' => 'center',
- ),
- ),
- 'render_callback' => 'render_block_core_tag_cloud',
- ) );
+ 'render_callback' => 'render_block_core_tag_cloud',
+ )
+ );
}
add_action( 'init', 'register_block_core_tag_cloud' );
From 52c4676a8bec0f6f5fd405c0a38870df3335c2b5 Mon Sep 17 00:00:00 2001
From: Javier Villanueva
Date: Tue, 9 Oct 2018 12:55:35 +0100
Subject: [PATCH 08/16] Move styles import to main editor.scss file
---
packages/block-library/src/editor.scss | 1 +
packages/block-library/src/tag-cloud/index.js | 1 -
2 files changed, 1 insertion(+), 1 deletion(-)
diff --git a/packages/block-library/src/editor.scss b/packages/block-library/src/editor.scss
index eb2dea826189bd..41d0c539eddc3b 100644
--- a/packages/block-library/src/editor.scss
+++ b/packages/block-library/src/editor.scss
@@ -29,3 +29,4 @@
@import "./text-columns/editor.scss";
@import "./verse/editor.scss";
@import "./video/editor.scss";
+@import "./tag-cloud/editor.scss";
diff --git a/packages/block-library/src/tag-cloud/index.js b/packages/block-library/src/tag-cloud/index.js
index 628668c23126af..cc785fdb3167a4 100644
--- a/packages/block-library/src/tag-cloud/index.js
+++ b/packages/block-library/src/tag-cloud/index.js
@@ -6,7 +6,6 @@ import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
-import './editor.scss';
import edit from './edit';
export const name = 'core/tag-cloud';
From 02980249de28afec6df20f2cb772c974dfa0c297 Mon Sep 17 00:00:00 2001
From: Javier Villanueva
Date: Fri, 18 Jan 2019 12:59:53 +0000
Subject: [PATCH 09/16] Add missing fixture files
---
.../full-content/fixtures/core__tag-cloud.parsed.json | 3 ++-
.../fixtures/core__tag-cloud__showTagCounts.parsed.json | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/test/integration/full-content/fixtures/core__tag-cloud.parsed.json b/test/integration/full-content/fixtures/core__tag-cloud.parsed.json
index e310f66541798f..cb601766c2b8e1 100644
--- a/test/integration/full-content/fixtures/core__tag-cloud.parsed.json
+++ b/test/integration/full-content/fixtures/core__tag-cloud.parsed.json
@@ -5,6 +5,7 @@
"taxonomy": "category"
},
"innerBlocks": [],
- "innerHTML": ""
+ "innerHTML": "",
+ "innerContent": []
}
]
diff --git a/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.parsed.json b/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.parsed.json
index 96d168f161eb8b..d9f82c35762450 100644
--- a/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.parsed.json
+++ b/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.parsed.json
@@ -6,6 +6,7 @@
"showTagCounts": true
},
"innerBlocks": [],
- "innerHTML": ""
+ "innerHTML": "",
+ "innerContent": []
}
]
From 716c1b4e16c448a566754c120c1450c91124f96e Mon Sep 17 00:00:00 2001
From: Javier Villanueva
Date: Sun, 27 Jan 2019 19:36:09 +0000
Subject: [PATCH 10/16] Misc fixes to tag cloud widget
---
packages/block-library/src/editor.scss | 2 +-
packages/block-library/src/index.js | 8 ++++--
packages/block-library/src/tag-cloud/edit.js | 28 ++++++++-----------
.../block-library/src/tag-cloud/editor.scss | 2 +-
.../block-library/src/tag-cloud/index.php | 14 ++++++----
5 files changed, 27 insertions(+), 27 deletions(-)
diff --git a/packages/block-library/src/editor.scss b/packages/block-library/src/editor.scss
index 41d0c539eddc3b..ff227a60eb8913 100644
--- a/packages/block-library/src/editor.scss
+++ b/packages/block-library/src/editor.scss
@@ -26,7 +26,7 @@
@import "./spacer/editor.scss";
@import "./subhead/editor.scss";
@import "./table/editor.scss";
+@import "./tag-cloud/editor.scss";
@import "./text-columns/editor.scss";
@import "./verse/editor.scss";
@import "./video/editor.scss";
-@import "./tag-cloud/editor.scss";
diff --git a/packages/block-library/src/index.js b/packages/block-library/src/index.js
index 0a956eaa03bcd8..fbfbbafc4a466a 100644
--- a/packages/block-library/src/index.js
+++ b/packages/block-library/src/index.js
@@ -91,12 +91,16 @@ export const registerCoreBlocks = () => {
spacer,
subhead,
table,
+ tagCloud,
template,
textColumns,
verse,
video,
- tagCloud,
- ].forEach( ( { name, settings } ) => {
+ ].forEach( ( block ) => {
+ if ( ! block ) {
+ return;
+ }
+ const { name, settings } = block;
registerBlockType( name, settings );
} );
diff --git a/packages/block-library/src/tag-cloud/edit.js b/packages/block-library/src/tag-cloud/edit.js
index f9765a248a0fd6..97d930a2c2477f 100644
--- a/packages/block-library/src/tag-cloud/edit.js
+++ b/packages/block-library/src/tag-cloud/edit.js
@@ -16,10 +16,6 @@ import {
} from '@wordpress/components';
import { withSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
-
-/**
- * Internal dependencies
- */
import { InspectorControls } from '@wordpress/editor';
class TagCloudEdit extends Component {
@@ -30,15 +26,20 @@ class TagCloudEdit extends Component {
this.toggleShowTagCounts = this.toggleShowTagCounts.bind( this );
}
- getTaxonomies() {
+ getTaxonomyOptions() {
const taxonomies = filter( this.props.taxonomies, 'show_cloud' );
-
- return map( taxonomies, ( taxonomy ) => {
+ const selectOption = {
+ label: __( '- Select -' ),
+ value: '',
+ };
+ const taxonomyOptions = map( taxonomies, ( taxonomy ) => {
return {
value: taxonomy.slug,
label: taxonomy.name,
};
} );
+
+ return [ selectOption, ...taxonomyOptions ];
}
setTaxonomy( taxonomy ) {
@@ -57,21 +58,14 @@ class TagCloudEdit extends Component {
render() {
const { attributes } = this.props;
const { taxonomy, showTagCounts } = attributes;
- const taxonomies = this.getTaxonomies();
- const options = [
- {
- label: __( '- Select -' ),
- value: '',
- },
- ...taxonomies,
- ];
+ const taxonomyOptions = this.getTaxonomyOptions();
const inspectorControls = (
@@ -95,7 +89,7 @@ class TagCloudEdit extends Component {
instructions={ __( 'Select a Taxonomy' ) }
>
diff --git a/packages/block-library/src/tag-cloud/editor.scss b/packages/block-library/src/tag-cloud/editor.scss
index ae00bc16dd8349..c70f1522860806 100644
--- a/packages/block-library/src/tag-cloud/editor.scss
+++ b/packages/block-library/src/tag-cloud/editor.scss
@@ -1,4 +1,4 @@
-.gutenberg .wp-block-tag-cloud {
+.block-editor .wp-block-tag-cloud {
a {
display: inline-block;
margin-right: 5px;
diff --git a/packages/block-library/src/tag-cloud/index.php b/packages/block-library/src/tag-cloud/index.php
index 3d0ded1a3f3865..c87415ad252151 100644
--- a/packages/block-library/src/tag-cloud/index.php
+++ b/packages/block-library/src/tag-cloud/index.php
@@ -2,7 +2,7 @@
/**
* Server-side rendering of the `core/tag-cloud` block.
*
- * @package gutenberg
+ * @package WordPress
*/
/**
@@ -13,19 +13,22 @@
* @return string Returns the tag cloud for selected taxonomy.
*/
function render_block_core_tag_cloud( $attributes ) {
- $class = "wp-block-tag-cloud align{$attributes['align']}";
- $wrapper_markup = '%2$s
';
+ if ( ! isset( $attributes['taxonomy'] ) ) {
+ return '';
+ }
+
+ $class = isset( $attributes['align'] ) ? "wp-block-tag-cloud align{$attributes['align']}" : 'wp-block-tag-cloud';
$args = array(
'echo' => false,
'taxonomy' => $attributes['taxonomy'],
- 'show_count' => ! empty( $attributes['showTagCounts'] ),
+ 'show_count' => $attributes['showTagCounts'],
);
$tag_cloud = wp_tag_cloud( $args );
$block_content = sprintf(
- $wrapper_markup,
+ '%2$s
',
esc_attr( $class ),
$tag_cloud
);
@@ -50,7 +53,6 @@ function register_block_core_tag_cloud() {
),
'align' => array(
'type' => 'string',
- 'default' => 'center',
),
),
'render_callback' => 'render_block_core_tag_cloud',
From 5d1d5d19c274e1940d15eb0163aa0f61c733b96c Mon Sep 17 00:00:00 2001
From: Javier Villanueva
Date: Sun, 27 Jan 2019 19:44:10 +0000
Subject: [PATCH 11/16] Update tag cloud fixtures
---
packages/block-library/src/tag-cloud/index.php | 2 +-
test/integration/full-content/fixtures/core__tag-cloud.json | 3 +--
.../full-content/fixtures/core__tag-cloud__showTagCounts.json | 3 +--
test/integration/full-content/server-registered.json | 2 +-
4 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/packages/block-library/src/tag-cloud/index.php b/packages/block-library/src/tag-cloud/index.php
index c87415ad252151..612d47777e4969 100644
--- a/packages/block-library/src/tag-cloud/index.php
+++ b/packages/block-library/src/tag-cloud/index.php
@@ -52,7 +52,7 @@ function register_block_core_tag_cloud() {
'default' => false,
),
'align' => array(
- 'type' => 'string',
+ 'type' => 'string',
),
),
'render_callback' => 'render_block_core_tag_cloud',
diff --git a/test/integration/full-content/fixtures/core__tag-cloud.json b/test/integration/full-content/fixtures/core__tag-cloud.json
index a75b9e2154778a..da9762c711adb4 100644
--- a/test/integration/full-content/fixtures/core__tag-cloud.json
+++ b/test/integration/full-content/fixtures/core__tag-cloud.json
@@ -5,8 +5,7 @@
"isValid": true,
"attributes": {
"taxonomy": "category",
- "showTagCounts": false,
- "align": "center"
+ "showTagCounts": false
},
"innerBlocks": [],
"originalContent": ""
diff --git a/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.json b/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.json
index cc73b1ec0e009f..5946f7330f8b55 100644
--- a/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.json
+++ b/test/integration/full-content/fixtures/core__tag-cloud__showTagCounts.json
@@ -5,8 +5,7 @@
"isValid": true,
"attributes": {
"taxonomy": "category",
- "showTagCounts": true,
- "align": "center"
+ "showTagCounts": true
},
"innerBlocks": [],
"originalContent": ""
diff --git a/test/integration/full-content/server-registered.json b/test/integration/full-content/server-registered.json
index 257a60f7908351..0062b0ced3c73c 100644
--- a/test/integration/full-content/server-registered.json
+++ b/test/integration/full-content/server-registered.json
@@ -1 +1 @@
-{"core\/block":{"attributes":{"ref":{"type":"number"}}},"core\/latest-comments":{"attributes":{"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},"align":{"type":"string","enum":["center","left","right","wide","full",""]}}},"core\/archives":{"attributes":{"align":{"type":"string"},"className":{"type":"string"},"displayAsDropdown":{"type":"boolean","default":false},"showPostCounts":{"type":"boolean","default":false}}},"core\/latest-posts":{"attributes":{"categories":{"type":"string"},"className":{"type":"string"},"postsToShow":{"type":"number","default":5},"displayPostDate":{"type":"boolean","default":false},"postLayout":{"type":"string","default":"list"},"columns":{"type":"number","default":3},"align":{"type":"string"},"order":{"type":"string","default":"desc"},"orderBy":{"type":"string","default":"date"}}},"core\/tag-cloud":{"attributes":{"taxonomy":{"type":"string"},"showTagCounts":{"type":"boolean","default":false},"align":{"type":"string","default":"center"}}}}
\ No newline at end of file
+{"core\/block":{"attributes":{"ref":{"type":"number"}}},"core\/latest-comments":{"attributes":{"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},"align":{"type":"string","enum":["center","left","right","wide","full",""]}}},"core\/archives":{"attributes":{"align":{"type":"string"},"className":{"type":"string"},"displayAsDropdown":{"type":"boolean","default":false},"showPostCounts":{"type":"boolean","default":false}}},"core\/latest-posts":{"attributes":{"categories":{"type":"string"},"className":{"type":"string"},"postsToShow":{"type":"number","default":5},"displayPostDate":{"type":"boolean","default":false},"postLayout":{"type":"string","default":"list"},"columns":{"type":"number","default":3},"align":{"type":"string"},"order":{"type":"string","default":"desc"},"orderBy":{"type":"string","default":"date"}}},"core\/tag-cloud":{"attributes":{"taxonomy":{"type":"string"},"showTagCounts":{"type":"boolean","default":false},"align":{"type":"string"}}}}
\ No newline at end of file
From 072072aa0beaf163d72267464f596c6d2addffaf Mon Sep 17 00:00:00 2001
From: Javier Villanueva
Date: Mon, 28 Jan 2019 10:25:31 +0000
Subject: [PATCH 12/16] Remove extra variable from render function
---
packages/block-library/src/tag-cloud/index.php | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/packages/block-library/src/tag-cloud/index.php b/packages/block-library/src/tag-cloud/index.php
index 612d47777e4969..3b1eb80d4568d4 100644
--- a/packages/block-library/src/tag-cloud/index.php
+++ b/packages/block-library/src/tag-cloud/index.php
@@ -17,7 +17,9 @@ function render_block_core_tag_cloud( $attributes ) {
return '';
}
- $class = isset( $attributes['align'] ) ? "wp-block-tag-cloud align{$attributes['align']}" : 'wp-block-tag-cloud';
+ $class = isset( $attributes['align'] ) ?
+ "wp-block-tag-cloud align{$attributes['align']}" :
+ 'wp-block-tag-cloud';
$args = array(
'echo' => false,
@@ -27,13 +29,11 @@ function render_block_core_tag_cloud( $attributes ) {
$tag_cloud = wp_tag_cloud( $args );
- $block_content = sprintf(
+ return sprintf(
'%2$s
',
esc_attr( $class ),
$tag_cloud
);
-
- return $block_content;
}
/**
From f36eab683a39ba5fac8c66c5d1f6d1f8023dd842 Mon Sep 17 00:00:00 2001
From: Javier Villanueva
Date: Mon, 4 Feb 2019 19:18:04 +0000
Subject: [PATCH 13/16] Misc a11y changes to tag cloud widget
---
packages/block-library/src/tag-cloud/edit.js | 31 ++++++++++++++++---
.../block-library/src/tag-cloud/index.php | 16 +++++++---
.../full-content/server-registered.json | 2 +-
3 files changed, 40 insertions(+), 9 deletions(-)
diff --git a/packages/block-library/src/tag-cloud/edit.js b/packages/block-library/src/tag-cloud/edit.js
index 97d930a2c2477f..2471bcba9fe7a4 100644
--- a/packages/block-library/src/tag-cloud/edit.js
+++ b/packages/block-library/src/tag-cloud/edit.js
@@ -13,15 +13,20 @@ import {
ToggleControl,
SelectControl,
ServerSideRender,
+ Toolbar,
} from '@wordpress/components';
import { withSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
-import { InspectorControls } from '@wordpress/editor';
+import { BlockControls, InspectorControls } from '@wordpress/editor';
class TagCloudEdit extends Component {
constructor() {
super( ...arguments );
+ this.state = {
+ editing: ! this.props.attributes.taxonomy,
+ };
+
this.setTaxonomy = this.setTaxonomy.bind( this );
this.toggleShowTagCounts = this.toggleShowTagCounts.bind( this );
}
@@ -45,6 +50,8 @@ class TagCloudEdit extends Component {
setTaxonomy( taxonomy ) {
const { setAttributes } = this.props;
+ this.setState( { editing: false } );
+
setAttributes( { taxonomy } );
}
@@ -56,10 +63,25 @@ class TagCloudEdit extends Component {
}
render() {
+ const { editing } = this.state;
const { attributes } = this.props;
const { taxonomy, showTagCounts } = attributes;
const taxonomyOptions = this.getTaxonomyOptions();
+ const toolbarControls = [
+ {
+ icon: 'edit',
+ title: __( 'Edit Taxonomy' ),
+ onClick: () => this.setState( { editing: true } ),
+ },
+ ];
+
+ const blockControls = (
+
+
+
+ );
+
const inspectorControls = (
@@ -70,7 +92,7 @@ class TagCloudEdit extends Component {
onChange={ this.setTaxonomy }
/>
@@ -78,7 +100,7 @@ class TagCloudEdit extends Component {
);
- if ( ! taxonomy ) {
+ if ( ! taxonomy || editing ) {
return (
{ inspectorControls }
@@ -86,9 +108,9 @@ class TagCloudEdit extends Component {
key="placeholder"
icon="tag"
label={ __( 'Tag Cloud' ) }
- instructions={ __( 'Select a Taxonomy' ) }
>
@@ -99,6 +121,7 @@ class TagCloudEdit extends Component {
return (
+ { blockControls }
{ inspectorControls }
false,
'taxonomy' => $attributes['taxonomy'],
@@ -27,6 +27,10 @@ function render_block_core_tag_cloud( $attributes ) {
$tag_cloud = wp_tag_cloud( $args );
+ if ( ! $tag_cloud ) {
+ $tag_cloud = esc_html( __( 'No taxonomies to show.' ) );
+ }
+
$block_content = sprintf(
'%2$s
',
esc_attr( $class ),
@@ -45,6 +49,10 @@ function register_block_core_tag_cloud() {
array(
'attributes' => array(
'taxonomy' => array(
+ 'type' => 'string',
+ 'default' => 'tags',
+ ),
+ 'className' => array(
'type' => 'string',
),
'showTagCounts' => array(
diff --git a/test/integration/full-content/server-registered.json b/test/integration/full-content/server-registered.json
index 0062b0ced3c73c..080865f39bb108 100644
--- a/test/integration/full-content/server-registered.json
+++ b/test/integration/full-content/server-registered.json
@@ -1 +1 @@
-{"core\/block":{"attributes":{"ref":{"type":"number"}}},"core\/latest-comments":{"attributes":{"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},"align":{"type":"string","enum":["center","left","right","wide","full",""]}}},"core\/archives":{"attributes":{"align":{"type":"string"},"className":{"type":"string"},"displayAsDropdown":{"type":"boolean","default":false},"showPostCounts":{"type":"boolean","default":false}}},"core\/latest-posts":{"attributes":{"categories":{"type":"string"},"className":{"type":"string"},"postsToShow":{"type":"number","default":5},"displayPostDate":{"type":"boolean","default":false},"postLayout":{"type":"string","default":"list"},"columns":{"type":"number","default":3},"align":{"type":"string"},"order":{"type":"string","default":"desc"},"orderBy":{"type":"string","default":"date"}}},"core\/tag-cloud":{"attributes":{"taxonomy":{"type":"string"},"showTagCounts":{"type":"boolean","default":false},"align":{"type":"string"}}}}
\ No newline at end of file
+{"core\/block":{"attributes":{"ref":{"type":"number"}}},"core\/latest-comments":{"attributes":{"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},"align":{"type":"string","enum":["center","left","right","wide","full",""]}}},"core\/archives":{"attributes":{"align":{"type":"string"},"className":{"type":"string"},"displayAsDropdown":{"type":"boolean","default":false},"showPostCounts":{"type":"boolean","default":false}}},"core\/latest-posts":{"attributes":{"categories":{"type":"string"},"className":{"type":"string"},"postsToShow":{"type":"number","default":5},"displayPostDate":{"type":"boolean","default":false},"postLayout":{"type":"string","default":"list"},"columns":{"type":"number","default":3},"align":{"type":"string"},"order":{"type":"string","default":"desc"},"orderBy":{"type":"string","default":"date"}}},"core\/tag-cloud":{"attributes":{"taxonomy":{"type":"string","default":"tags"},"className":{"type":"string"},"showTagCounts":{"type":"boolean","default":false},"align":{"type":"string"}}}}
\ No newline at end of file
From a5d3608fdb2c0dbf054551fd2666eb39d3151694 Mon Sep 17 00:00:00 2001
From: Javier Villanueva
Date: Mon, 4 Feb 2019 22:37:29 +0000
Subject: [PATCH 14/16] Change tag taxonomy name
---
packages/block-library/src/tag-cloud/edit.js | 1 +
packages/block-library/src/tag-cloud/index.php | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/packages/block-library/src/tag-cloud/edit.js b/packages/block-library/src/tag-cloud/edit.js
index 2471bcba9fe7a4..d515ff29645acb 100644
--- a/packages/block-library/src/tag-cloud/edit.js
+++ b/packages/block-library/src/tag-cloud/edit.js
@@ -111,6 +111,7 @@ class TagCloudEdit extends Component {
>
diff --git a/packages/block-library/src/tag-cloud/index.php b/packages/block-library/src/tag-cloud/index.php
index 0fd7024d75956e..b54928a1c66c88 100644
--- a/packages/block-library/src/tag-cloud/index.php
+++ b/packages/block-library/src/tag-cloud/index.php
@@ -50,7 +50,7 @@ function register_block_core_tag_cloud() {
'attributes' => array(
'taxonomy' => array(
'type' => 'string',
- 'default' => 'tags',
+ 'default' => 'post_tag',
),
'className' => array(
'type' => 'string',
From 3315bce3cc52611c6738133e485cf4dc5c9d1cff Mon Sep 17 00:00:00 2001
From: Robert Anderson
Date: Thu, 14 Feb 2019 11:57:48 +0000
Subject: [PATCH 15/16] Remove extra parameters in taxonomies query
Co-Authored-By: jahvi
---
packages/block-library/src/tag-cloud/edit.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packages/block-library/src/tag-cloud/edit.js b/packages/block-library/src/tag-cloud/edit.js
index d515ff29645acb..47443c38f76b55 100644
--- a/packages/block-library/src/tag-cloud/edit.js
+++ b/packages/block-library/src/tag-cloud/edit.js
@@ -136,6 +136,6 @@ class TagCloudEdit extends Component {
export default withSelect( ( select ) => {
return {
- taxonomies: select( 'core' ).getTaxonomies( { per_page: -1 } ),
+ taxonomies: select( 'core' ).getTaxonomies(),
};
} )( TagCloudEdit );
From 2d5e7b9b9c819f3afa979bb96ca9928636846961 Mon Sep 17 00:00:00 2001
From: Javier Villanueva
Date: Thu, 14 Feb 2019 21:02:24 +0000
Subject: [PATCH 16/16] Remove placeholder view from tag cloud
---
packages/block-library/src/tag-cloud/edit.js | 42 +------------------
.../block-library/src/tag-cloud/index.php | 2 +-
2 files changed, 2 insertions(+), 42 deletions(-)
diff --git a/packages/block-library/src/tag-cloud/edit.js b/packages/block-library/src/tag-cloud/edit.js
index 47443c38f76b55..2fb7179e2ca221 100644
--- a/packages/block-library/src/tag-cloud/edit.js
+++ b/packages/block-library/src/tag-cloud/edit.js
@@ -9,15 +9,13 @@ import { map, filter } from 'lodash';
import { Component, Fragment } from '@wordpress/element';
import {
PanelBody,
- Placeholder,
ToggleControl,
SelectControl,
ServerSideRender,
- Toolbar,
} from '@wordpress/components';
import { withSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
-import { BlockControls, InspectorControls } from '@wordpress/editor';
+import { InspectorControls } from '@wordpress/editor';
class TagCloudEdit extends Component {
constructor() {
@@ -50,8 +48,6 @@ class TagCloudEdit extends Component {
setTaxonomy( taxonomy ) {
const { setAttributes } = this.props;
- this.setState( { editing: false } );
-
setAttributes( { taxonomy } );
}
@@ -63,25 +59,10 @@ class TagCloudEdit extends Component {
}
render() {
- const { editing } = this.state;
const { attributes } = this.props;
const { taxonomy, showTagCounts } = attributes;
const taxonomyOptions = this.getTaxonomyOptions();
- const toolbarControls = [
- {
- icon: 'edit',
- title: __( 'Edit Taxonomy' ),
- onClick: () => this.setState( { editing: true } ),
- },
- ];
-
- const blockControls = (
-
-
-
- );
-
const inspectorControls = (
@@ -100,29 +81,8 @@ class TagCloudEdit extends Component {
);
- if ( ! taxonomy || editing ) {
- return (
-
- { inspectorControls }
-
-
-
-
- );
- }
-
return (
- { blockControls }
{ inspectorControls }