diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index 92542e0..9bd3bc1 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -7,10 +7,8 @@ template: | categories: - title: '🚀 Features' - collapse-after: 3 label: 'enhancement' - title: '🐛 Bug Fixes' - collapse-after: 3 labels: - 'fix' - 'bugfix' diff --git a/includes/query-loop.php b/includes/query-loop.php index 5be064b..547c4fb 100644 --- a/includes/query-loop.php +++ b/includes/query-loop.php @@ -58,7 +58,7 @@ function ( $pre_render, $parsed_block ) { 'query_loop_block_query_vars', function ( $default_query, $block ) { // Retrieve the query from the passed block context. - $block_query = $block->context['query'] ?? []; + $block_query = $block->context['query'] ?? array(); // Process all of the params $qpg = new Query_Params_Generator( $default_query, $block_query ); @@ -127,6 +127,7 @@ function add_more_sort_by( $query_params ) { $query_params['orderby']['enum'][] = 'rand'; $query_params['orderby']['enum'][] = 'post__in'; $query_params['orderby']['enum'][] = 'comment_count'; + $query_params['orderby']['enum'][] = 'name'; return $query_params; } diff --git a/src/components/post-date-query-controls.js b/src/components/post-date-query-controls.js index b6ffd30..a6ee39e 100644 --- a/src/components/post-date-query-controls.js +++ b/src/components/post-date-query-controls.js @@ -75,7 +75,10 @@ export const PostDateQueryControls = ( { attributes, setAttributes } ) => { value={ relationFromQuery } disabled={ range !== '' } options={ [ - { label: __( 'None', 'advanced-query-loop' ), value: '' }, + { + label: __( 'None', 'advanced-query-loop' ), + value: '', + }, { label: __( 'Before', 'advanced-query-loop' ), value: 'before', diff --git a/src/components/post-order-controls.js b/src/components/post-order-controls.js index df094f1..4ca267c 100644 --- a/src/components/post-order-controls.js +++ b/src/components/post-order-controls.js @@ -4,6 +4,57 @@ import { SelectControl, ToggleControl } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; +export const sortOptions = [ + { + label: __( 'Name', 'advanced-query-loop' ), + value: 'name', + }, + { + label: __( 'Author', 'advanced-query-loop' ), + value: 'author', + }, + { + label: __( 'Comment Count', 'advanced-query-loop' ), + value: 'comment_count', + }, + { + label: __( 'Date', 'advanced-query-loop' ), + value: 'date', + }, + { + label: __( 'Included Posts', 'advanced-query-loop' ), + value: 'post__in', + }, + { + label: __( 'Last Modified Date', 'advanced-query-loop' ), + value: 'modified', + }, + { + label: __( 'Menu Order', 'advanced-query-loop' ), + value: 'menu_order', + }, + { + label: __( 'Meta Value', 'advanced-query-loop' ), + value: 'meta_value', + }, + { + label: __( 'Meta Value Num', 'advanced-query-loop' ), + value: 'meta_value_num', + }, + { + label: __( 'Post ID', 'advanced-query-loop' ), + value: 'id', + }, + { + label: __( 'Random', 'advanced-query-loop' ), + value: 'rand', + }, + { + label: __( 'Title', 'advanced-query-loop' ), + value: 'title', + }, +]; + /** * PostOrderControls component * @@ -25,55 +76,9 @@ export const PostOrderControls = ( { attributes, setAttributes } ) => { ) : '' } - options={ [ - { - label: __( 'Author', 'advanced-query-loop' ), - value: 'author', - }, - { - label: __( 'Comment Count', 'advanced-query-loop' ), - value: 'comment_count', - }, - { - label: __( 'Date', 'advanced-query-loop' ), - value: 'date', - }, - { - label: __( 'Included Posts', 'advanced-query-loop' ), - value: 'post__in', - }, - { - label: __( - 'Last Modified Date', - 'advanced-query-loop' - ), - value: 'modified', - }, - { - label: __( 'Menu Order', 'advanced-query-loop' ), - value: 'menu_order', - }, - { - label: __( 'Meta Value', 'advanced-query-loop' ), - value: 'meta_value', - }, - { - label: __( 'Meta Value Num', 'advanced-query-loop' ), - value: 'meta_value_num', - }, - { - label: __( 'Post ID', 'advanced-query-loop' ), - value: 'id', - }, - { - label: __( 'Random', 'advanced-query-loop' ), - value: 'rand', - }, - { - label: __( 'Title', 'advanced-query-loop' ), - value: 'title', - }, - ] } + options={ sortOptions.sort( ( a, b ) => + a.label.localeCompare( b.label ) + ) } onChange={ ( newOrderBy ) => { setAttributes( { query: { diff --git a/src/variations/controls.js b/src/variations/controls.js index 6d2394b..9a604d5 100644 --- a/src/variations/controls.js +++ b/src/variations/controls.js @@ -5,6 +5,7 @@ import { addFilter } from '@wordpress/hooks'; import { InspectorControls } from '@wordpress/block-editor'; import { PanelBody } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; +import { createBlock } from '@wordpress/blocks'; /** * Internal dependencies */ @@ -92,4 +93,51 @@ const withAdvancedQueryControls = ( BlockEdit ) => ( props ) => { return ; }; -addFilter( 'editor.BlockEdit', 'core/query', withAdvancedQueryControls ); +addFilter( + 'editor.BlockEdit', + 'aql/add-add-controls/core/query', + withAdvancedQueryControls +); + +/** + * Filter to add AQL transform to core/query block + * + * @param {Object} settings + * @param {string} name + * @return {Object} settings + */ +function addAQLTransforms( settings, name ) { + if ( name !== 'core/query' ) { + return settings; + } + + return { + ...settings, + keywords: [ ...settings.keywords, 'AQL', 'aql' ], + transforms: { + to: settings?.transforms?.to || [], + from: [ + ...( settings?.transforms?.from || [] ), + { + type: 'enter', + regExp: /^(AQL|aql)$/, + transform: () => { + return createBlock( + 'core/query', + { + namespace: 'advanced-query-loop', + }, + [] + ); + }, + }, + ], + }, + }; +} + +addFilter( + 'blocks.registerBlockType', + 'aql/add-transforms/query-block', + addAQLTransforms +);