PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / trunk
Secure Custom Fields vtrunk
6.9.1 6.9.0 6.8.9 6.8.7 6.8.8 6.8.6 6.8.4 6.8.5 trunk 6.4.0-beta1 6.4.0-beta2 6.4.1 6.4.1-beta3 6.4.1-beta4 6.4.1-beta5 6.4.1-beta6 6.4.1-beta7 6.4.2 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.5.5 6.5.6 6.5.7 6.6.0 6.7.0 6.7.1 6.8.0 6.8.1 6.8.2 6.8.3
secure-custom-fields / assets / src / js / bindings / sources.js
secure-custom-fields / assets / src / js / bindings Last commit date
block-editor.js 6 months ago constants.js 6 months ago field-processing.js 6 months ago fieldMetadataCache.js 6 months ago hooks.js 6 months ago index.js 11 months ago sources.js 6 months ago utils.js 6 months ago
sources.js
92 lines
1 /**
2 * WordPress dependencies
3 */
4 import { registerBlockBindingsSource } from '@wordpress/blocks';
5 import { store as coreDataStore } from '@wordpress/core-data';
6 import { store as editorStore } from '@wordpress/editor';
7 import { __ } from '@wordpress/i18n';
8
9 /**
10 * Internal dependencies
11 */
12 import {
13 getSCFFields,
14 processFieldBinding,
15 formatFieldLabel,
16 } from './field-processing';
17 import { getFieldMetadata } from './fieldMetadataCache';
18
19 /**
20 * Register the SCF field binding source.
21 */
22 registerBlockBindingsSource( {
23 name: 'acf/field',
24 label: __( 'SCF Fields', 'secure-custom-fields' ),
25 getLabel( { args, select } ) {
26 const fieldKey = args?.key;
27
28 if ( ! fieldKey ) {
29 return __( 'SCF Fields', 'secure-custom-fields' );
30 }
31
32 const fieldMetadata = getFieldMetadata( fieldKey );
33
34 if ( fieldMetadata?.label ) {
35 return fieldMetadata.label;
36 }
37
38 return formatFieldLabel( fieldKey );
39 },
40 getValues( { context, bindings, select } ) {
41 const { getCurrentPostType } = select( editorStore );
42 const currentPostType = getCurrentPostType();
43 const isSiteEditor = currentPostType === 'wp_template';
44
45 // In site editor, return field labels as placeholder values
46 if ( isSiteEditor ) {
47 const result = {};
48 Object.entries( bindings ).forEach(
49 ( [ attribute, { args } = {} ] ) => {
50 const fieldKey = args?.key;
51 if ( ! fieldKey ) {
52 result[ attribute ] = '';
53 return;
54 }
55
56 const fieldMetadata = getFieldMetadata( fieldKey );
57 result[ attribute ] =
58 fieldMetadata?.label || formatFieldLabel( fieldKey );
59 }
60 );
61 return result;
62 }
63
64 // Regular post editor - get actual field values
65 const { getEditedEntityRecord } = select( coreDataStore );
66
67 const post =
68 context?.postType && context?.postId
69 ? getEditedEntityRecord(
70 'postType',
71 context.postType,
72 context.postId
73 )
74 : undefined;
75
76 const scfFields = getSCFFields( post );
77 const result = {};
78
79 Object.entries( bindings ).forEach(
80 ( [ attribute, { args } = {} ] ) => {
81 const value = processFieldBinding( attribute, args, scfFields );
82 result[ attribute ] = value;
83 }
84 );
85
86 return result;
87 },
88 canUserEditValue() {
89 return false;
90 },
91 } );
92