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

Query loop / Post template: Enable post format filter #64167

Merged
merged 65 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
1bbceed
Enable post format filter in the query loop
carolinan Aug 1, 2024
d12d992
try to fix CS issues
carolinan Aug 1, 2024
e803527
how about this cs fix then?
carolinan Aug 1, 2024
ada8db4
Create a new option for post formats
carolinan Aug 2, 2024
63883ac
Update the control to use the post format theme support
carolinan Aug 5, 2024
800ee24
Post template preview: Get the ID of the post format to use in the qu…
carolinan Aug 5, 2024
ac44e6f
Filter the query loop vars to support post formats on the front.
carolinan Aug 6, 2024
63bad0f
Remove the post type from PostFormatControls
carolinan Aug 6, 2024
6f6e3e8
PHPCS fixes
carolinan Aug 6, 2024
d5ad75b
Merge branch 'trunk' into try/post-format-query
carolinan Aug 12, 2024
7482122
Update the condition for when then post format control should show
carolinan Aug 13, 2024
d3fa212
WIP: Try to add format to the REST API posts controller through a cus…
carolinan Aug 13, 2024
ca718ef
Merge branch 'trunk' into try/post-format-query
carolinan Aug 13, 2024
4ab896c
Update since
carolinan Aug 13, 2024
367f6c1
Regenerate the fixture for the query loop, including postFormat.
carolinan Aug 13, 2024
2f6e716
Revert removing the post formats from TaxonomyControls
carolinan Aug 13, 2024
def06f2
Update class-gutenberg-rest-posts-controller-6-7.php
carolinan Aug 13, 2024
8d87706
Combine the post format with the tax_query array instead of replacing…
carolinan Aug 13, 2024
7a989f9
WIP: comment out breaking code to allow testing.
carolinan Aug 13, 2024
976bb04
Merge branch 'trunk' into try/post-format-query
carolinan Aug 22, 2024
7008f76
edit.js: Don't convert the post format to a string
carolinan Aug 22, 2024
7c6ac16
Update edit.js
carolinan Aug 22, 2024
5154069
Simplify the format array in get_item_schema
carolinan Aug 22, 2024
c09d093
Remove the changes to get_collection_params()
carolinan Aug 22, 2024
713786e
Allow filtering for the standard post format
carolinan Aug 22, 2024
c7d7c88
Filter register_post_type_args instead of using rest_api_init
carolinan Aug 22, 2024
96b408b
Merge branch 'trunk' into try/post-format-query
carolinan Aug 27, 2024
c13e920
Rename "postFormat" parameter to "format"
carolinan Aug 27, 2024
bf67232
Merge branch 'trunk' into try/post-format-query
carolinan Aug 29, 2024
a1a561b
Add format to get_collection_params()
carolinan Aug 29, 2024
b87d25c
Update lib/compat/wordpress-6.7/class-gutenberg-rest-posts-controller…
carolinan Aug 29, 2024
4786c24
Update class-gutenberg-rest-posts-controller-6-7.php
carolinan Aug 29, 2024
c41fbbb
Merge branch 'try/post-format-query' of https://github.com/WordPress/…
carolinan Aug 29, 2024
78470b0
PHPCS: remove white space
carolinan Aug 29, 2024
8f32caf
Remove get_item_schema()
carolinan Aug 29, 2024
deab94c
Update the logic for the standard post format in gutenberg_filter_qu…
carolinan Aug 29, 2024
c4d9e1d
Replace SelectControl with FormTokenField
carolinan Aug 30, 2024
f2f9045
Merge branch 'trunk' into try/post-format-query
carolinan Aug 31, 2024
e2b82d3
Set the constant format to an empty array when format is not queried
carolinan Aug 31, 2024
5739bf3
Hide the control and reset the format value if the post type does not…
carolinan Sep 1, 2024
90fbdd9
Rename postFormatSupportMap to postTypeFormatSupportMap
carolinan Sep 1, 2024
1573c10
Merge branch 'trunk' into try/post-format-query
carolinan Sep 1, 2024
33119d7
Merge branch 'trunk' into try/post-format-query
carolinan Sep 3, 2024
a1017ef
Fix REST API controller override condition
Mamaduka Sep 4, 2024
601644f
Don't set the default post format in the schema
Mamaduka Sep 4, 2024
8eab071
Satisfy PHP linter
Mamaduka Sep 4, 2024
8121870
Update the 'FormatsControl' to match suggestion labels to their stati…
Mamaduka Sep 4, 2024
1b291ed
Refactor showFormatControl logic
Mamaduka Sep 4, 2024
d31086d
Merge branch 'trunk' into try/post-format-query
carolinan Sep 5, 2024
e798f3b
gutenberg_filter_query_loop_block_query_vars_post_format: Switch to u…
carolinan Sep 5, 2024
664b745
Update lib/compat/wordpress-6.7/post-formats.php
carolinan Sep 5, 2024
812c372
End the comment with a full stop.
carolinan Sep 5, 2024
2e7e901
Merge branch 'trunk' into try/post-format-query
carolinan Sep 9, 2024
ce0583b
Update doc blocks and replace aray_diff with unset and array_search.
carolinan Sep 9, 2024
83d02bc
Update doc block
carolinan Sep 9, 2024
9cbe2ad
Add backport changelog
carolinan Sep 9, 2024
4b46ea2
Oops: Fix the copy-paste typo in the changelog entry.
carolinan Sep 9, 2024
d98fbaa
Update lib/compat/wordpress-6.7/class-gutenberg-rest-posts-controller…
carolinan Sep 10, 2024
9514a05
Rename gutenberg_filter_query_loop_block_query_vars_post_format to gu…
carolinan Sep 10, 2024
a702271
Gutenberg_REST_Posts_Controller_6_7 get_items: remove the array conve…
carolinan Sep 10, 2024
4df4639
Add two checks that help fail gracefully when errors occur
carolinan Sep 11, 2024
25ceeec
Update the docBlock for gutenberg_add_format_query_vars_to_query_loop…
carolinan Sep 11, 2024
a85a919
FormatControls: simplify array conversion
carolinan Sep 11, 2024
f182af0
Merge branch 'trunk' into try/post-format-query
carolinan Sep 13, 2024
8031da7
Merge branch 'trunk' into try/post-format-query
carolinan Sep 16, 2024
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
22 changes: 22 additions & 0 deletions lib/compat/wordpress-6.7/taxonomy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Temporary compatibility code for post formats.
*
* @package gutenberg
*/

/**
* Add support for the post format taxonomy in the REST API.
* See wp-includes/taxonomy.php line 170.
*
* Needed to add post formats to the taxonomy filter in the query loop.
*
* @since 6.7.0
*/
add_filter(
'register_post_format_taxonomy_args',
function ( $args ) {
$args['show_in_rest'] = true;
carolinan marked this conversation as resolved.
Show resolved Hide resolved
return $args;
}
);
1 change: 1 addition & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ function gutenberg_is_experiment_enabled( $name ) {
// WordPress 6.7 compat.
require __DIR__ . '/compat/wordpress-6.7/blocks.php';
require __DIR__ . '/compat/wordpress-6.7/block-bindings.php';
require __DIR__ . '/compat/wordpress-6.7/taxonomy.php';

// Experimental features.
require __DIR__ . '/experimental/block-editor-settings-mobile.php';
Expand Down
11 changes: 10 additions & 1 deletion packages/block-library/src/post-template/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export default function PostTemplateEdit( {
taxQuery,
parents,
pages,
postFormat,
// We gather extra query args to pass to the REST API call.
// This way extenders of Query Loop can add their own query args,
// and have accurate previews in the editor.
Expand Down Expand Up @@ -138,7 +139,10 @@ export default function PostTemplateEdit( {
( { slug } ) => slug === taxonomySlug
);
if ( taxonomy?.rest_base ) {
accumulator[ taxonomy?.rest_base ] = terms;
// Skip post formats, as they are handled separately.
if ( ! taxonomy.rest_base === 'post_format' ) {
carolinan marked this conversation as resolved.
Show resolved Hide resolved
accumulator[ taxonomy.rest_base ] = terms;
}
}
return accumulator;
},
Expand All @@ -163,6 +167,10 @@ export default function PostTemplateEdit( {
if ( parents?.length ) {
query.parent = parents;
}
if ( postFormat?.length ) {
query.post_format = postFormat;
}

// If sticky is not set, it will return all posts in the results.
// If sticky is set to `only`, it will limit the results to sticky posts only.
// If it is anything else, it will exclude sticky posts from results. For the record the value stored is `exclude`.
Expand Down Expand Up @@ -205,6 +213,7 @@ export default function PostTemplateEdit( {
templateSlug,
taxQuery,
parents,
postFormat,
restQueryArgs,
previewPostType,
]
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/query/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"sticky": "",
"inherit": true,
"taxQuery": null,
"parents": []
"parents": [],
"postFormat": []
}
},
"tagName": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import OrderControl from './order-control';
import AuthorControl from './author-control';
import ParentControl from './parent-control';
import { TaxonomyControls } from './taxonomy-controls';
import PostFormatControls from './post-format-controls';
import StickyControl from './sticky-control';
import EnhancedPaginationControl from './enhanced-pagination-control';
import CreateNewPostLink from './create-new-post-link';
Expand Down Expand Up @@ -52,6 +53,7 @@ export default function QueryInspectorControls( props ) {
inherit,
taxQuery,
parents,
postFormat,
carolinan marked this conversation as resolved.
Show resolved Hide resolved
} = query;
const allowedControls = useAllowedControls( attributes );
const [ showSticky, setShowSticky ] = useState( postType === 'post' );
Expand Down Expand Up @@ -127,12 +129,15 @@ export default function QueryInspectorControls( props ) {
const showParentControl =
isControlAllowed( allowedControls, 'parents' ) &&
isPostTypeHierarchical;
const showPostFormatControl =
carolinan marked this conversation as resolved.
Show resolved Hide resolved
taxonomies && taxonomies.some( ( { slug } ) => slug === 'post_format' );

const showFiltersPanel =
showTaxControl ||
showAuthorControl ||
showSearchControl ||
showParentControl;
showParentControl ||
showPostFormatControl;
const dropdownMenuProps = useToolsPanelDropdownMenuProps();

return (
Expand Down Expand Up @@ -263,6 +268,7 @@ export default function QueryInspectorControls( props ) {
parents: [],
search: '',
taxQuery: null,
postFormat: [],
} );
setQuerySearch( '' );
} }
Expand Down Expand Up @@ -324,6 +330,18 @@ export default function QueryInspectorControls( props ) {
/>
</ToolsPanelItem>
) }
{ showPostFormatControl && (
<ToolsPanelItem
hasValue={ () => !! postFormat?.length }
label={ __( 'Formats' ) }
onDeselect={ () => setQuery( { postFormat: [] } ) }
>
<PostFormatControls
onChange={ setQuery }
query={ query }
/>
</ToolsPanelItem>
) }
</ToolsPanel>
) }
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* WordPress dependencies
*/
import { SelectControl } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { decodeEntities } from '@wordpress/html-entities';
import { __ } from '@wordpress/i18n';

export default function PostFormatControls( { onChange, query } ) {
const { postType, postFormat } = query;

const { postFormats } = useSelect(
( select ) => {
const { getEntityRecords } = select( coreStore );
return {
postFormats: getEntityRecords( 'taxonomy', 'post_format', {
carolinan marked this conversation as resolved.
Show resolved Hide resolved
order: 'asc',
_fields: 'id,name',
context: 'view',
per_page: -1,
post_type: postType,
} ),
};
},
[ postType ]
);

const postFormatOptions = postFormats
? [
{ value: '', label: __( 'All' ) },
...postFormats.map( ( { id, name } ) => ( {
value: id,
label: decodeEntities( name ),
} ) ),
]
: [ { value: '', label: __( 'All' ) } ];

return (
<SelectControl
__nextHasNoMarginBottom
__next40pxDefaultSize
label={ __( 'Formats' ) }
value={ postFormat }
options={ postFormatOptions }
onChange={ ( value ) => {
onChange( { postFormat: value } );
} }
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,16 @@ const getTermIdByTermValue = ( terms, termValue ) => {
export function TaxonomyControls( { onChange, query } ) {
const { postType, taxQuery } = query;

const taxonomies = useTaxonomies( postType );
let taxonomies = useTaxonomies( postType );
if ( ! taxonomies || taxonomies.length === 0 ) {
return null;
}

// Remove post formats, as they are handled separately.
taxonomies = taxonomies.filter(
( taxonomy ) => taxonomy.slug !== 'post_format'
);

return (
<VStack spacing={ 4 }>
{ taxonomies.map( ( taxonomy ) => {
Expand Down
Loading