-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathpost-meta.js
52 lines (48 loc) · 1.21 KB
/
post-meta.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* WordPress dependencies
*/
import { useEntityProp } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';
import { _x } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import { store as editorStore } from '../store';
export default {
name: 'core/post-meta',
label: _x( 'Post Meta', 'block bindings source' ),
useSource( props, sourceAttributes ) {
const { getCurrentPostType } = useSelect( editorStore );
const { context } = props;
const { key: metaKey } = sourceAttributes;
const postType = context.postType
? context.postType
: getCurrentPostType();
const [ meta, setMeta ] = useEntityProp(
'postType',
context.postType,
'meta',
context.postId
);
if ( postType === 'wp_template' ) {
return { placeholder: metaKey };
}
const metaValue = meta[ metaKey ];
const updateMetaValue = ( newValue ) => {
setMeta( { ...meta, [ metaKey ]: newValue } );
};
return {
placeholder: metaKey,
value: metaValue,
updateValue: updateMetaValue,
};
},
settings: {
blocks: {
'core/paragraph': [ 'content' ],
'core/heading': [ 'content' ],
'core/image': [ 'url', 'title', 'alt' ],
'core/button': [ 'url', 'text', 'linkTarget' ],
},
},
};