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

Block Library: Mark new blocks to be included in WordPress core #40186

Merged
merged 4 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
53 changes: 53 additions & 0 deletions lib/compat/wordpress-6.0/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,56 @@ function gutenberg_block_type_metadata_multiple_view_scripts( $metadata ) {
return $metadata;
}
add_filter( 'block_type_metadata', 'gutenberg_block_type_metadata_multiple_view_scripts' );

/**
* Workaround for getting discussion settings as block editor settings
* so any user can access to them without needing to be an admin.
*
* @param array $settings Default editor settings.
*
* @return array Filtered editor settings.
*/
function gutenberg_extend_block_editor_settings_with_discussion_settings( $settings ) {

$settings['__experimentalDiscussionSettings'] = array(
'commentOrder' => get_option( 'comment_order' ),
'commentsPerPage' => get_option( 'comments_per_page' ),
'defaultCommentsPage' => get_option( 'default_comments_page' ),
'pageComments' => get_option( 'page_comments' ),
'threadComments' => get_option( 'thread_comments' ),
'threadCommentsDepth' => get_option( 'thread_comments_depth' ),
'avatarURL' => get_avatar_url(
'',
array(
'size' => 96,
'force_default' => true,
'default' => get_option( 'avatar_default' ),
)
),
);

return $settings;
}
add_filter( 'block_editor_settings_all', 'gutenberg_extend_block_editor_settings_with_discussion_settings' );

/**
* Mark the `children` attr of comments as embeddable so they can be included in
* REST API responses without additional requests.
*
* @return void
*/
function gutenberg_rest_comment_set_children_as_embeddable() {
add_filter(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@c4rl0sbr4v0 and @DAreRodz - is that still necessary for the Comment Template block?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need that function in order to show Comment Replies on the editor. Attached a video of what happens if we remove it.

removing_rest_extension.mov

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thank you for the confirmation 👍🏻

'rest_prepare_comment',
function ( $response ) {
$links = $response->get_links();
if ( isset( $links['children'] ) ) {
$href = $links['children'][0]['href'];
$response->remove_link( 'children', $href );
$response->add_link( 'children', $href, array( 'embeddable' => true ) );
}
return $response;
}
);
}
add_action( 'rest_api_init', 'gutenberg_rest_comment_set_children_as_embeddable' );
57 changes: 0 additions & 57 deletions lib/experimental/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,63 +96,6 @@ function get_comments_pagination_arrow( $block, $pagination_type = 'next' ) {
}
}

if ( ! function_exists( 'extend_block_editor_settings_with_discussion_settings' ) ) {
/**
* Workaround for getting discussion settings as block editor settings
* so any user can access to them without needing to be an admin.
*
* @param array $settings Default editor settings.
*
* @return array Filtered editor settings.
*/
function extend_block_editor_settings_with_discussion_settings( $settings ) {

$settings['__experimentalDiscussionSettings'] = array(
'commentOrder' => get_option( 'comment_order' ),
'commentsPerPage' => get_option( 'comments_per_page' ),
'defaultCommentsPage' => get_option( 'default_comments_page' ),
'pageComments' => get_option( 'page_comments' ),
'threadComments' => get_option( 'thread_comments' ),
'threadCommentsDepth' => get_option( 'thread_comments_depth' ),
'avatarURL' => get_avatar_url(
'',
array(
'size' => 96,
'force_default' => true,
'default' => get_option( 'avatar_default' ),
)
),
);

return $settings;
}
}
add_filter( 'block_editor_settings_all', 'extend_block_editor_settings_with_discussion_settings' );

if ( ! function_exists( 'gutenberg_rest_comment_set_children_as_embeddable' ) ) {
/**
* Mark the `children` attr of comments as embeddable so they can be included in
* REST API responses without additional requests.
*
* @return void
*/
function gutenberg_rest_comment_set_children_as_embeddable() {
add_filter(
'rest_prepare_comment',
function ( $response ) {
$links = $response->get_links();
if ( isset( $links['children'] ) ) {
$href = $links['children'][0]['href'];
$response->remove_link( 'children', $href );
$response->add_link( 'children', $href, array( 'embeddable' => true ) );
}
return $response;
}
);
}
}
add_action( 'rest_api_init', 'gutenberg_rest_comment_set_children_as_embeddable' );

/**
* Returns whether the quote v2 is enabled by the user.
*
Expand Down
30 changes: 15 additions & 15 deletions packages/block-library/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ export const __experimentalGetCoreBlocks = () => [
siteTagline,
query,
templatePart,
avatar,
postTitle,
postExcerpt,
postFeaturedImage,
Expand All @@ -204,7 +205,21 @@ export const __experimentalGetCoreBlocks = () => [
queryPaginationNext,
queryPaginationNumbers,
queryPaginationPrevious,
queryNoResults,
readMore,
commentAuthorName,
commentContent,
commentDate,
commentEditLink,
commentReplyLink,
commentTemplate,
commentsQueryLoop,
commentsPagination,
commentsPaginationNext,
commentsPaginationNumbers,
commentsPaginationPrevious,
postComments,
homeLink,
logInOut,
termDescription,
queryTitle,
Expand Down Expand Up @@ -252,31 +267,16 @@ export const __experimentalRegisterExperimentalCoreBlocks = process.env
? ( { enableFSEBlocks } = {} ) => {
[
// Experimental blocks.
avatar,
homeLink,
postAuthorName,
queryNoResults,
// Full Site Editing blocks.
...( enableFSEBlocks
? [
commentAuthorAvatar,
commentAuthorName,
commentContent,
commentDate,
commentEditLink,
commentReplyLink,
commentTemplate,
commentsQueryLoop,
commentsPagination,
commentsPaginationNext,
commentsPaginationNumbers,
commentsPaginationPrevious,
navigationArea,
postComment,
postCommentsCount,
postCommentsForm,
postCommentsLink,
readMore,
]
: [] ),
].forEach( registerBlock );
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/post-comment/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import { blockDefault } from '@wordpress/icons';
import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';

const ALLOWED_BLOCKS = [
'core/comment-author-avatar',
'core/avatar',
'core/comment-author-name',
'core/comment-content',
'core/comment-date',
'core/comment-edit-link',
'core/comment-reply-link',
];
const TEMPLATE = [
[ 'core/comment-author-avatar' ],
[ 'core/avatar' ],
[ 'core/comment-author-name' ],
[ 'core/comment-date' ],
[ 'core/comment-content' ],
Expand Down