-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Framework: Bootstrap Block Templates #3668
Conversation
7a8ded7
to
64ab4db
Compare
Codecov Report
@@ Coverage Diff @@
## master #3668 +/- ##
=========================================
- Coverage 37.32% 37.3% -0.02%
=========================================
Files 277 277
Lines 6685 6690 +5
Branches 1213 1214 +1
=========================================
+ Hits 2495 2496 +1
- Misses 3532 3536 +4
Partials 658 658
Continue to review full report at Codecov.
|
editor/effects.js
Outdated
const effects = []; | ||
|
||
// Parse content as blocks | ||
if ( post.content.raw ) { | ||
effects.push( resetBlocks( parse( post.content.raw ) ) ); | ||
} else if ( settings.template ) { | ||
const blocks = map( settings.template.blocks, ( { name, attributes } ) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure we are going to want additional properties on the template
object instead of making template = template.blocks
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know honestly. Server-side I think so, because templates could have a name/description but client-side I don't really know. I thought we should do this to avoid future breaking changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, just thinking out-loud. There are things like "locking" which might be interesting there. Not sure about naming templates, but maybe an id / slug
if they are stored somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking further, I can't see why we would pair defining blocks and naming in the CPT. If anything, the "template" would be defined outside the CPT and referenced here by slug.
Also, things like locking could be defined as another attribute of the CPT registration, which seems more in line with how we generally structure options:
'template' => array(
array( 'core/image' ),
array( 'core/paragraph', array(
'placeholder' => 'Add a book description',
) ),
array( 'core/quote' ),
),
'template_lock' => true,
Finally, what do you think of simplifying the syntax to not require name => 'core/heading'
? I think we can rely on the definition of a block to be array( blockName, attributes ... )
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I was not sure about the extra keys anyway.
editor/effects.js
Outdated
}; | ||
return block; | ||
} ); | ||
effects.push( resetBlocks( blocks ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love that this fairly low profile implementation wise.
64ab4db
to
55454fe
Compare
This is looking good to me. We probably want to add a test and some documentation. I think we might need a new "Templates" document. (Doesn't have to block this.) |
Merged, let's add the docs and tests separately. |
@@ -782,6 +782,11 @@ function gutenberg_editor_scripts_and_styles( $hook ) { | |||
'blockTypes' => $allowed_block_types, | |||
); | |||
|
|||
$post_type_object = get_post_type_object( $post_to_edit['type'] ); | |||
if ( $post_type_object->template ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notice: Undefined property: WP_Post_Type::$template in /srv/www/editor/htdocs/wp-content/plugins/gutenberg/lib/client-assets.php on line 786
I suggest running with high error reporting:
error_reporting( E_ALL );
(Add near top of site root index.php
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You want empty
here:
if ( ! empty( $post_type_object->template ) ) {
I'm not sure if this is intended, but omitting |
@iamhexcoder Yes, this is expected. Gutenberg uses the REST API and if the We'll figure out a way to solve this. Tracked in #3066 |
This PR is the first one introducing the Block Templates. (details on those here #3588 )
This first iteration allows:
A template object looks like this:
Testing instructions
Notes