-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsite-editor.js
More file actions
31 lines (26 loc) · 988 Bytes
/
site-editor.js
File metadata and controls
31 lines (26 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* globals newspack_block_theme_subtitle_block */
/**
* WordPress dependencies
*/
import { registerBlockType } from '@wordpress/blocks';
import { useBlockProps } from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';
import { Icon, listView } from '@wordpress/icons';
import { useEntityProp } from '@wordpress/core-data';
import metadata from './block.json';
const EditComponent = ( { context: { postType, postId } = {} } ) => {
const blockProps = useBlockProps();
const [ postMeta = {} ] = useEntityProp( 'postType', postType, 'meta', postId );
const subtitle = postMeta[ newspack_block_theme_subtitle_block.post_meta_name ] || __( 'Article subtitle', 'newspack-block-theme' );
return <p { ...blockProps }>{ subtitle }</p>;
};
const blockData = {
title: __( 'Article Subtitle', 'newspack-block-theme' ),
icon: {
src: <Icon icon={ listView } />,
foreground: '#36f',
},
edit: EditComponent,
...metadata,
};
registerBlockType( metadata.name, blockData );