Skip to content

Commit e2ec61e

Browse files
committed
- introduces support for graphql_description_after when using register_graphql_acf_field_type, allowing for a string or callback to be passed that will append a string to the description which is populated by the field graphql_description or instructions field.
- implements this on the DatePicker and DateTimePicker field types to show that the string will be output in RFC3339 format - updates the description of the startDate and endDate fields of the ACFE_Date_Range type to include a link to the RFC3339 spec
1 parent 5d500c0 commit e2ec61e

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

src/FieldConfig.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ protected function is_supported_field_type(): bool {
135135
*/
136136
public function get_field_description(): string {
137137

138+
$graphql_field_type = $this->get_graphql_field_type();
139+
$field_type_config = ( $graphql_field_type instanceof AcfGraphQLFieldType ) ? $graphql_field_type->get_config() : [];
140+
138141
// Use the explicit graphql_description, if set
139142
if ( ! empty( $this->acf_field['graphql_description'] ) ) {
140143
$description = $this->acf_field['graphql_description'];
@@ -153,6 +156,15 @@ public function get_field_description(): string {
153156
);
154157
}
155158

159+
if ( isset( $field_type_config['graphql_description_after'] ) ) {
160+
161+
if ( is_callable( $field_type_config['graphql_description_after'] ) ) {
162+
$description .= ' ' . call_user_func( $field_type_config['graphql_description_after'], $this );
163+
} else {
164+
$description .= ' ' . $field_type_config['graphql_description_after'];
165+
}
166+
}
167+
156168
return $description;
157169
}
158170

src/FieldType/DatePicker.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ public static function register_field_type(): void {
1313
'date_picker',
1414
[
1515
'graphql_type' => 'String',
16+
// Apply a description to be appended to the field description.
17+
// @todo: consider removing when CustomScalar types are supported along with the @specifiedBy directive
18+
'graphql_description_after' => function( FieldConfig $field_config ) {
19+
$field_type = $field_config->get_acf_field()['type'] ?? null;
20+
21+
return '(' . sprintf( __( 'ACF Fields of the %s type return a date string in the format `YYYYMMDD` according to the RFC3339 spec: https://datatracker.ietf.org/doc/html/rfc3339.', 'wp-graphql-acf' ), $field_type ) . ')';
22+
},
1623
'resolve' => static function ( $root, $args, $context, $info, $field_type, FieldConfig $field_config ) {
1724
$value = $field_config->resolve_field( $root, $args, $context, $info );
1825

src/FieldType/DateTimePicker.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ public static function register_field_type(): void {
1414
'date_time_picker',
1515
[
1616
'graphql_type' => 'String',
17+
// Apply a description to be appended to the field description.
18+
// @todo: consider removing when CustomScalar types are supported along with the @specifiedBy directive
19+
'graphql_description_after' => function( FieldConfig $field_config ) {
20+
$field_type = $field_config->get_acf_field()['type'] ?? null;
21+
22+
return '(' . sprintf( __( 'ACF Fields of the %s type return a date string in the format `YYYYMMDD` according to the RFC3339 spec: https://datatracker.ietf.org/doc/html/rfc3339.', 'wp-graphql-acf' ), $field_type ) . ')';
23+
},
1724
'resolve' => static function ( $root, $args, $context, $info, $field_type, FieldConfig $field_config ) {
1825
$value = $field_config->resolve_field( $root, $args, $context, $info );
1926

src/FieldType/FlexibleContent.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ static function ( $field ) use ( $layout ) {
7373
)
7474
);
7575

76-
$layout['sub_fields'] = array_merge( $sub_fields, $layout['sub_fields'] );
76+
$layout_sub_fields = ! empty( $layout['sub_fields'] ) && is_array( $layout['sub_fields'] ) ? $layout['sub_fields'] : [];
77+
78+
$layout['sub_fields'] = array_merge( $sub_fields, $layout_sub_fields );
7779

7880
$layouts[] = $layout;
7981
}

src/ThirdParty/AcfExtended/AcfExtended.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,12 @@ public function register_initial_types(): void {
339339
'startDate' => [
340340
// @todo: DATETIME Scalar
341341
'type' => 'String',
342-
'description' => __( 'The start date of a date range returned as an RFC 3339 time string', 'wpgraphql-acf' ),
342+
'description' => __( 'The start date of a date range returned as an RFC 3339 time string (https://datatracker.ietf.org/doc/html/rfc3339)', 'wpgraphql-acf' ),
343343
],
344344
'endDate' => [
345345
// @todo: DATETIME Scalar
346346
'type' => 'String',
347-
'description' => __( 'The start date of a date range RFC 3339 time string', 'wpgraphql-acf' ),
347+
'description' => __( 'The start date of a date range RFC 3339 time string (https://datatracker.ietf.org/doc/html/rfc3339)', 'wpgraphql-acf' ),
348348
],
349349
],
350350
]

0 commit comments

Comments
 (0)