diff --git a/core-blocks/archives/edit.js b/core-blocks/archives/edit.js new file mode 100644 index 00000000000000..0a53c463a47d14 --- /dev/null +++ b/core-blocks/archives/edit.js @@ -0,0 +1,55 @@ +/** + * WordPress dependencies + */ +import { Fragment } from '@wordpress/element'; +import { + PanelBody, + ServerSideRender, + ToggleControl, + Disabled, +} from '@wordpress/components'; +import { __ } from '@wordpress/i18n'; + +/** + * Internal dependencies + */ +import { + InspectorControls, + BlockAlignmentToolbar, + BlockControls, +} from '@wordpress/editor'; + +export default function ArchivesEdit( { attributes, setAttributes } ) { + const { align, showPostCounts, displayAsDropdown } = attributes; + + return ( + + + + setAttributes( { showPostCounts: ! showPostCounts } ) } + /> + setAttributes( { displayAsDropdown: ! displayAsDropdown } ) } + /> + + + + { + setAttributes( { align: nextAlign } ); + } } + controls={ [ 'left', 'center', 'right' ] } + /> + + + + + + ); +} diff --git a/core-blocks/archives/index.js b/core-blocks/archives/index.js new file mode 100644 index 00000000000000..8a4e5e6531e656 --- /dev/null +++ b/core-blocks/archives/index.js @@ -0,0 +1,39 @@ +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; + +/** + * Internal dependencies + */ +import edit from './edit'; + +export const name = 'core/archives'; + +export const settings = { + title: __( 'Archives' ), + + description: __( 'Display a monthly archive of your site’s Posts.' ), + + icon: 'calendar-alt', + + category: 'widgets', + + supports: { + html: false, + }, + + getEditWrapperProps( attributes ) { + const { align } = attributes; + if ( 'left' === align || 'right' === align || 'center' === align ) { + return { 'data-align': align }; + } + }, + + edit, + + save() { + // Handled by PHP. + return null; + }, +}; diff --git a/core-blocks/archives/index.php b/core-blocks/archives/index.php new file mode 100644 index 00000000000000..9c221590e5c31d --- /dev/null +++ b/core-blocks/archives/index.php @@ -0,0 +1,111 @@ + 'monthly', + 'format' => 'option', + 'show_post_count' => $show_post_count, + ) ); + + $dropdown_args['echo'] = 0; + + $archives = wp_get_archives( $dropdown_args ); + + switch ( $dropdown_args['type'] ) { + case 'yearly': + $label = __( 'Select Year', 'gutenberg' ); + break; + case 'monthly': + $label = __( 'Select Month', 'gutenberg' ); + break; + case 'daily': + $label = __( 'Select Day', 'gutenberg' ); + break; + case 'weekly': + $label = __( 'Select Week', 'gutenberg' ); + break; + default: + $label = __( 'Select Post', 'gutenberg' ); + break; + } + + $label = esc_attr( $label ); + + $block_content = ' + '; + + $block_content = sprintf( + '
%2$s
', + esc_attr( $class ), + $block_content + ); + } else { + + /** This filter is documented in wp-includes/widgets/class-wp-widget-archives.php */ + $archives_args = apply_filters( 'widget_archives_args', array( + 'type' => 'monthly', + 'show_post_count' => $show_post_count, + ) ); + + $archives_args['echo'] = 0; + + $block_content = wp_get_archives( $archives_args ); + + $block_content = sprintf( + '', + esc_attr( $class ), + $block_content + ); + } + + return $block_content; +} + +/** + * Register archives block. + */ +function register_block_core_archives() { + register_block_type( 'core/archives', array( + 'attributes' => array( + 'showPostCounts' => array( + 'type' => 'boolean', + 'default' => false, + ), + 'displayAsDropdown' => array( + 'type' => 'boolean', + 'default' => false, + ), + 'align' => array( + 'type' => 'string', + 'default' => 'none', + ), + ), + 'render_callback' => 'render_block_core_archives', + ) ); +} + +add_action( 'init', 'register_block_core_archives' ); diff --git a/core-blocks/index.js b/core-blocks/index.js index 6782e3c5b6ef69..89366bdc8a071f 100644 --- a/core-blocks/index.js +++ b/core-blocks/index.js @@ -16,6 +16,7 @@ import * as image from './image'; import * as heading from './heading'; import * as quote from './quote'; import * as gallery from './gallery'; +import * as archives from './archives'; import * as audio from './audio'; import * as button from './button'; import * as categories from './categories'; @@ -56,6 +57,7 @@ export const registerCoreBlocks = () => { // Register all remaining core blocks. shortcode, + archives, audio, button, categories, diff --git a/core-blocks/test/fixtures/core__archives.html b/core-blocks/test/fixtures/core__archives.html new file mode 100644 index 00000000000000..68bda3aaef3fdf --- /dev/null +++ b/core-blocks/test/fixtures/core__archives.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/core-blocks/test/fixtures/core__archives.json b/core-blocks/test/fixtures/core__archives.json new file mode 100644 index 00000000000000..27fd284777b07b --- /dev/null +++ b/core-blocks/test/fixtures/core__archives.json @@ -0,0 +1,10 @@ +[ + { + "uid": "_uid_0", + "name": "core/archives", + "isValid": true, + "attributes": {}, + "innerBlocks": [], + "originalContent": "" + } +] diff --git a/core-blocks/test/fixtures/core__archives.parsed.json b/core-blocks/test/fixtures/core__archives.parsed.json new file mode 100644 index 00000000000000..f883870399030b --- /dev/null +++ b/core-blocks/test/fixtures/core__archives.parsed.json @@ -0,0 +1,11 @@ +[ + { + "blockName": "core/archives", + "attrs": { + "showPostCounts": false, + "displayAsDropdown": false + }, + "innerBlocks": [], + "innerHTML": "" + } +] diff --git a/core-blocks/test/fixtures/core__archives.serialized.html b/core-blocks/test/fixtures/core__archives.serialized.html new file mode 100644 index 00000000000000..b8928752375cd9 --- /dev/null +++ b/core-blocks/test/fixtures/core__archives.serialized.html @@ -0,0 +1 @@ + diff --git a/core-blocks/test/fixtures/core__archives__showPostCounts.html b/core-blocks/test/fixtures/core__archives__showPostCounts.html new file mode 100644 index 00000000000000..bd1c93d1e1d336 --- /dev/null +++ b/core-blocks/test/fixtures/core__archives__showPostCounts.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/core-blocks/test/fixtures/core__archives__showPostCounts.json b/core-blocks/test/fixtures/core__archives__showPostCounts.json new file mode 100644 index 00000000000000..27fd284777b07b --- /dev/null +++ b/core-blocks/test/fixtures/core__archives__showPostCounts.json @@ -0,0 +1,10 @@ +[ + { + "uid": "_uid_0", + "name": "core/archives", + "isValid": true, + "attributes": {}, + "innerBlocks": [], + "originalContent": "" + } +] diff --git a/core-blocks/test/fixtures/core__archives__showPostCounts.parsed.json b/core-blocks/test/fixtures/core__archives__showPostCounts.parsed.json new file mode 100644 index 00000000000000..b016ecf02288de --- /dev/null +++ b/core-blocks/test/fixtures/core__archives__showPostCounts.parsed.json @@ -0,0 +1,11 @@ +[ + { + "blockName": "core/archives", + "attrs": { + "showPostCounts": true, + "displayAsDropdown": false + }, + "innerBlocks": [], + "innerHTML": "" + } +] diff --git a/core-blocks/test/fixtures/core__archives__showPostCounts.serialized.html b/core-blocks/test/fixtures/core__archives__showPostCounts.serialized.html new file mode 100644 index 00000000000000..b8928752375cd9 --- /dev/null +++ b/core-blocks/test/fixtures/core__archives__showPostCounts.serialized.html @@ -0,0 +1 @@ +