-
Notifications
You must be signed in to change notification settings - Fork 2
Add the colophon block #29
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
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| "$schema": "https://schemas.wp.org/trunk/block.json", | ||
| "apiVersion": 3, | ||
| "name": "team51/colophon", | ||
| "version": "0.1.0", | ||
| "title": "Colophon", | ||
| "category": "theme", | ||
| "icon": "editor-textcolor", | ||
| "description": "A block for displaying a colophon.", | ||
| "supports": { | ||
| "html": false, | ||
| "align": true, | ||
| "typography": { | ||
| "fontSize": true, | ||
| "lineHeight": true, | ||
| "__experimentalFontFamily": true, | ||
| "__experimentalFontStyle": true, | ||
| "__experimentalFontWeight": true, | ||
| "__experimentalLetterSpacing": true, | ||
| "__experimentalTextTransform": true, | ||
| "__experimentalDefaultControls": { | ||
| "fontSize": true | ||
| } | ||
| } | ||
| }, | ||
| "textdomain": "team51-blocks", | ||
| "editorScript": "file:./index.js", | ||
| "render": "file:./render.php" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /** | ||
| * Import the ServerSideRender component from the @wordpress/server-side-render package. | ||
| * This component is used to render the block on the server side. | ||
| * | ||
| * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-server-side-render/ | ||
| */ | ||
| import ServerSideRender from "@wordpress/server-side-render"; | ||
|
|
||
| /** | ||
| * React hook that is used to mark the block wrapper element. | ||
| * It provides all the necessary props like the class name. | ||
| * | ||
| * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops | ||
| */ | ||
| import { useBlockProps } from "@wordpress/block-editor"; | ||
|
|
||
| /** | ||
| * Import the block.json to get the block meta. | ||
| */ | ||
| import blockMeta from "./block.json"; | ||
|
|
||
| /** | ||
| * The edit function describes the structure of your block in the context of the | ||
| * editor. This represents what the editor will render when the block is used. | ||
| * | ||
| * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#edit | ||
| * | ||
| * @return {WPElement} Element to render. | ||
| */ | ||
| export default function Edit(props) { | ||
| return ( | ||
| <div {...useBlockProps()}> | ||
| <ServerSideRender | ||
| block={blockMeta.name} | ||
| attributes={props.attributes} | ||
| /> | ||
| </div> | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /** | ||
| * Registers a new block provided a unique name and an object defining its behavior. | ||
| * | ||
| * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/ | ||
| */ | ||
| import { registerBlockType } from "@wordpress/blocks"; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import Edit from "./edit"; | ||
| import metadata from "./block.json"; | ||
|
|
||
| /** | ||
| * Every block starts by registering a new block type definition. | ||
| * | ||
| * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/ | ||
| */ | ||
| registerBlockType(metadata.name, { | ||
| /** | ||
| * @see ./edit.js | ||
| */ | ||
| edit: Edit, | ||
|
|
||
| /** | ||
| * @see ./save.js | ||
| */ | ||
| save: () => null, | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <div <?php echo wp_kses_data( get_block_wrapper_attributes() ); ?>> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I use it because it is there in the example for dynamic block. |
||
| <?php do_action( 'team51_credits' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ?> | ||
| </div> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| "$schema": "https://schemas.wp.org/trunk/block.json", | ||
| "apiVersion": 3, | ||
| "name": "team51/colophon", | ||
| "version": "0.1.0", | ||
| "title": "Colophon", | ||
| "category": "theme", | ||
| "icon": "editor-textcolor", | ||
| "description": "A block for displaying a colophon.", | ||
| "supports": { | ||
| "html": false, | ||
| "align": true, | ||
| "typography": { | ||
| "fontSize": true, | ||
| "lineHeight": true, | ||
| "__experimentalFontFamily": true, | ||
| "__experimentalFontStyle": true, | ||
| "__experimentalFontWeight": true, | ||
| "__experimentalLetterSpacing": true, | ||
| "__experimentalTextTransform": true, | ||
| "__experimentalDefaultControls": { | ||
| "fontSize": true | ||
| } | ||
| } | ||
| }, | ||
| "textdomain": "team51-blocks", | ||
| "editorScript": "file:./index.js", | ||
| "render": "file:./render.php" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-server-side-render'), 'version' => '3eead5c1aa4c3d8aaba2'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <div <?php echo wp_kses_data( get_block_wrapper_attributes() ); ?>> | ||
| <?php do_action( 'team51_credits' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ?> | ||
| </div> |
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 know block context can be used to set a block where it can only be used in a post context or the like --
https://developer.wordpress.org/block-editor/reference-guides/block-api/block-context/
Is there an option we can set so that the block is only usable in a FSE / page template context, so we're not cluttering up the block options when someone's writing a post?
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.
Blocks meant for use in FSE themes are called Theme Blocks, and I think this would be the way to do it:
https://github.com/WordPress/gutenberg/blob/e706d67c7482e752a4adaae3e0b0449234e19902/packages/block-library/src/navigation/block.json#L6
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.
Currently, even if using
themeas the category for the theme block. It is still visible in the post editor. The only option I can think of now is to remove the block programatically on the post editor. Should we go that route?