4
4
import { __ } from '@wordpress/i18n' ;
5
5
import { registerBlockBindingsSource } from '@wordpress/blocks' ;
6
6
import { store as coreDataStore } from '@wordpress/core-data' ;
7
+ import { dateI18n } from '@wordpress/date' ;
7
8
8
9
/**
9
10
* Get the value of a specific field from the ACF fields.
@@ -43,12 +44,19 @@ registerBlockBindingsSource( {
43
44
)
44
45
: undefined ;
45
46
const result = { } ;
46
-
47
47
Object . entries ( bindings ) . forEach (
48
48
( [ attribute , { args } = { } ] ) => {
49
49
const fieldName = args ?. key ;
50
-
50
+ const mergedFields = fields ?. scf_field_groups
51
+ ? Object . fromEntries (
52
+ fields . scf_field_groups
53
+ . flatMap ( ( group ) => group . fields || [ ] )
54
+ . map ( ( field ) => [ field . name , field ] )
55
+ )
56
+ : { } ;
51
57
const fieldValue = getFieldValue ( fields , fieldName ) ;
58
+ const fieldType = mergedFields [ fieldName ] ?. type ;
59
+
52
60
if ( typeof fieldValue === 'object' && fieldValue !== null ) {
53
61
let value = '' ;
54
62
@@ -59,7 +67,7 @@ registerBlockBindingsSource( {
59
67
}
60
68
61
69
result [ attribute ] = value ;
62
- } else if ( typeof fieldValue === 'number' ) {
70
+ } else if ( 'number' === typeof fieldValue ) {
63
71
if ( attribute === 'content' ) {
64
72
result [ attribute ] = fieldValue . toString ( ) || '' ;
65
73
} else {
@@ -69,6 +77,12 @@ registerBlockBindingsSource( {
69
77
attribute
70
78
) ;
71
79
}
80
+ } else if ( 'date_picker' === fieldType && fieldValue ) {
81
+ result [ attribute ] =
82
+ dateI18n (
83
+ mergedFields [ fieldName ] ?. display_format ,
84
+ fieldValue
85
+ ) || '' ;
72
86
} else {
73
87
result [ attribute ] = fieldValue || '' ;
74
88
}
0 commit comments