WordPress at 5.0
Miles Elliott - @milesdelliott
An object that describe how the block will pull data from the HTML
attributes: {
content: {
type: 'array',
source: 'children',
selector: 'h1,h2,h3,h4,h5,h6',
},
nodeName: {
type: 'string',
source: 'property',
selector: 'h1,h2,h3,h4,h5,h6',
property: 'nodeName',
default: 'H2',
},
align: {
type: 'string',
},
placeholder: {
type: 'string',
},
},
Describes how that data turns into HTML.
Basically a functional react component
Includes portals to control areas
edit( { ... ) {
return [
isSelected && (
<BlockControls />
),
isSelected && (
<InspectorControls key="inspector">
<Toolbar />
<AlignmentToolbar />
</InspectorControls>
),
<RichText
key="editable"
wrapperClassName="wp-block-heading"
tagName={ nodeName.toLowerCase() }
value={ content }
onChange={ ( value ) =>
setAttributes( { content: value } ) }
onMerge={ mergeBlocks }
/>,
];
},
Similar to the edit method but the control portals are gone and the editable component is replaced
save( { attributes } ) {
const { ... } = attributes;
const Tag = nodeName.toLowerCase();
return (
<Tag style={ { textAlign: align } } >
{ content }
</Tag>
);
},
Uses HTML comments to denote where blocks begin and end, which block it is, and some of the data. Other data is pulled from the HTML
<!-- wp:heading {"align":"center","className":"My Heading Link"} -->
<h2 style="text-align:center" class="My Heading Link">
<a href="https://ncsu.edu">
<strong>Headings</strong> <del>for</del> <em>Days</em>
</a>
</h2>
<!-- /wp:heading -->
Similar to the markup in the data base but without the comments
<h2 style="text-align:center" class="My Heading Link">
<a href="https://ncsu.edu">
<strong>Headings</strong> <del>for</del> <em>Days</em>
</a>
</h2>
'template' => array(
array( 'core/columns', array("className"=>"grid-2-col"), array(
array( 'core/heading', array( 'content' => 'Details', 'layout' => 'column-1' ) ),
array( 'core/heading', array( 'placeholder' => 'Enter Details', 'layout' => 'column-1' ) ),
array( 'core/heading', array( 'content' => 'Address', 'layout' => 'column-2' ) ),
array( 'core/heading', array( 'placeholder' => 'Enter Address', 'layout' => 'column-2' ) ),
) )