Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
123 changes: 0 additions & 123 deletions lib/class-wp-rest-blocks-controller.php

This file was deleted.

3 changes: 0 additions & 3 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
// These files only need to be loaded if within a rest server instance
// which this class will exist if that is the case.
if ( class_exists( 'WP_REST_Controller' ) ) {
if ( ! class_exists( 'WP_REST_Blocks_Controller' ) ) {
require dirname( __FILE__ ) . '/class-wp-rest-blocks-controller.php';
}
if ( ! class_exists( 'WP_REST_Autosaves_Controller' ) ) {
require dirname( __FILE__ ) . '/class-wp-rest-autosaves-controller.php';
}
Expand Down
26 changes: 14 additions & 12 deletions lib/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,25 +439,27 @@ function gutenberg_register_post_types() {
register_post_type(
'wp_block',
array(
'labels' => array(
'labels' => array(
'name' => __( 'Blocks', 'gutenberg' ),
'singular_name' => __( 'Block', 'gutenberg' ),
'search_items' => __( 'Search Blocks', 'gutenberg' ),
),
'public' => false,
'show_ui' => true,
'show_in_menu' => false,
'rewrite' => false,
'show_in_rest' => true,
'rest_base' => 'blocks',
'rest_controller_class' => 'WP_REST_Blocks_Controller',
'capability_type' => 'block',
'capabilities' => array(
'public' => false,
'show_ui' => true,
'show_in_menu' => false,
'rewrite' => false,
'show_in_rest' => true,
'rest_base' => 'blocks',
'capability_type' => 'block',
'capabilities' => array(
'read' => 'read_blocks',
'create_posts' => 'create_blocks',
),
'map_meta_cap' => true,
'supports' => false,
'map_meta_cap' => true,
'supports' => array(
'title',
'editor',
),
Copy link
Member

Choose a reason for hiding this comment

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

Because the CPT now supports title and editor, we can go a step further and remove this line from gutenberg.php:267:

unset( $actions['edit'] );

This PR would then close #9964.

Copy link
Member Author

Choose a reason for hiding this comment

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

Because the CPT now supports title and editor, we can go a step further and remove this line from gutenberg.php:267:

Updated in c8ad73a

)
);

Expand Down
31 changes: 17 additions & 14 deletions packages/editor/src/store/effects/reusable-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
getBlocks,
getBlocksByClientId,
} from '../selectors';
import { getPostRawValue } from '../reducer';

/**
* Module Constants
Expand All @@ -61,26 +62,25 @@ export const fetchReusableBlocks = async ( action, store ) => {

let result;
if ( id ) {
result = apiFetch( { path: `/wp/v2/${ postType.rest_base }/${ id }` } );
result = apiFetch( { path: `/wp/v2/${ postType.rest_base }/${ id }?context=edit` } );
} else {
result = apiFetch( { path: `/wp/v2/${ postType.rest_base }?per_page=-1` } );
result = apiFetch( { path: `/wp/v2/${ postType.rest_base }?per_page=-1&context=edit` } );
}

try {
const reusableBlockOrBlocks = await result;
dispatch( receiveReusableBlocksAction( map(
castArray( reusableBlockOrBlocks ),
( reusableBlock ) => {
const parsedBlocks = parse( reusableBlock.content );
if ( parsedBlocks.length === 1 ) {
return {
reusableBlock,
parsedBlock: parsedBlocks[ 0 ],
};
}
( post ) => {
const parsedBlocks = parse( post.content.raw );
return {
reusableBlock,
parsedBlock: createBlock( 'core/template', {}, parsedBlocks ),
reusableBlock: {
id: post.id,
title: getPostRawValue( post.title ),
},
parsedBlock: parsedBlocks.length === 1 ?
parsedBlocks[ 0 ] :
createBlock( 'core/template', {}, parsedBlocks ),
};
}
) ) );
Expand Down Expand Up @@ -119,7 +119,7 @@ export const saveReusableBlocks = async ( action, store ) => {
const reusableBlock = getBlock( state, clientId );
const content = serialize( reusableBlock.name === 'core/template' ? reusableBlock.innerBlocks : reusableBlock );

const data = isTemporary ? { title, content } : { id, title, content };
const data = isTemporary ? { title, content, status: 'publish' } : { id, title, content, status: 'publish' };
const path = isTemporary ? `/wp/v2/${ postType.rest_base }` : `/wp/v2/${ postType.rest_base }/${ id }`;
const method = isTemporary ? 'POST' : 'PUT';

Expand Down Expand Up @@ -184,7 +184,10 @@ export const deleteReusableBlocks = async ( action, store ) => {
] ) );

try {
await apiFetch( { path: `/wp/v2/${ postType.rest_base }/${ id }`, method: 'DELETE' } );
await apiFetch( {
path: `/wp/v2/${ postType.rest_base }/${ id }?force=true`,
Copy link
Member

Choose a reason for hiding this comment

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

Thinking about this some more, I think we should remove the ?force=true so that deleting a reusable block in Gutenberg matches what happens when you delete a reusable block in the Manage Reusable Blocks interface.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm okay with this. As alluded to, seems like it would make sense to have this be controlled at the post-type level, for the sort of consistency you note. In the meantime, letting "Trashed" do its thing seems quite okay with me.

Copy link
Member Author

Choose a reason for hiding this comment

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

Related to this one, we'll need to do similar with the forced "Published" status.

method: 'DELETE',
} );
dispatch( {
type: 'DELETE_REUSABLE_BLOCK_SUCCESS',
id,
Expand Down
18 changes: 12 additions & 6 deletions packages/editor/src/store/effects/test/reusable-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,12 @@ describe( 'reusable blocks effects', () => {
const blockPromise = Promise.resolve( [
{
id: 123,
title: 'My cool block',
content: '<!-- wp:test-block {"name":"Big Bird"} /-->',
title: {
raw: 'My cool block',
},
content: {
raw: '<!-- wp:test-block {"name":"Big Bird"} /-->',
},
},
] );
const postTypePromise = Promise.resolve( {
Expand All @@ -97,7 +101,6 @@ describe( 'reusable blocks effects', () => {
reusableBlock: {
id: 123,
title: 'My cool block',
content: '<!-- wp:test-block {"name":"Big Bird"} /-->',
},
parsedBlock: expect.objectContaining( {
name: 'core/test-block',
Expand All @@ -115,8 +118,12 @@ describe( 'reusable blocks effects', () => {
it( 'should fetch a single reusable block', async () => {
const blockPromise = Promise.resolve( {
id: 123,
title: 'My cool block',
content: '<!-- wp:test-block {"name":"Big Bird"} /-->',
title: {
raw: 'My cool block',
},
content: {
raw: '<!-- wp:test-block {"name":"Big Bird"} /-->',
},
} );
const postTypePromise = Promise.resolve( {
slug: 'wp_block', rest_base: 'blocks',
Expand All @@ -141,7 +148,6 @@ describe( 'reusable blocks effects', () => {
reusableBlock: {
id: 123,
title: 'My cool block',
content: '<!-- wp:test-block {"name":"Big Bird"} /-->',
},
parsedBlock: expect.objectContaining( {
name: 'core/test-block',
Expand Down
13 changes: 8 additions & 5 deletions packages/list-reusable-blocks/src/utils/export.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { pick, kebabCase } from 'lodash';
import { kebabCase } from 'lodash';

/**
* WordPress dependencies
Expand All @@ -19,13 +19,16 @@ import { download } from './file';
* @param {number} id
*/
async function exportReusableBlock( id ) {
const postType = await apiFetch( { path: `/wp/v2/types/wp_block` } );
const reusableBlock = await apiFetch( { path: `/wp/v2/${ postType.rest_base }/${ id }` } );
const postType = await apiFetch( { path: `/wp/v2/types/wp_block?context=edit` } );
const post = await apiFetch( { path: `/wp/v2/${ postType.rest_base }/${ id }` } );
const title = post.title.raw;
const content = post.content.raw;
const fileContent = JSON.stringify( {
__file: 'wp_block',
...pick( reusableBlock, [ 'title', 'content' ] ),
title,
content,
}, null, 2 );
const fileName = kebabCase( reusableBlock.title ) + '.json';
const fileName = kebabCase( title ) + '.json';

download( fileName, fileContent, 'application/json' );
}
Expand Down
Loading