Skip to content

Commit 153761c

Browse files
authored
Merge pull request #190 from wp-graphql/release/v2.2.0
release: v2.2.0
2 parents 5d500c0 + 43b778d commit 153761c

File tree

17 files changed

+417
-29
lines changed

17 files changed

+417
-29
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Changelog
22

3+
## 2.2.0
4+
5+
## New Features
6+
7+
- [#181](https://github.com/wp-graphql/wpgraphql-acf/pull/181): feat: update docs Date fields to link to the RFC3339 spec
8+
9+
### Chores / Bugfixes
10+
11+
- [#182](https://github.com/wp-graphql/wpgraphql-acf/pull/182): fix: admin_enqueue_scripts callback should expect a possible null value passed to it
12+
- [#185](https://github.com/wp-graphql/wpgraphql-acf/pull/185): fix: clone field within a group field type returns null values
13+
- [#189](https://github.com/wp-graphql/wpgraphql-acf/pull/189): fix: image fields (and other connection fields) not properly resolving when queried asPreview
14+
315
## 2.1.2
416

517
### Chores / Bugfixes

readme.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Tags: GraphQL, ACF, API, NextJS, Faust, Headless, Decoupled, React, Vue, Svelte,
44
Requires at least: 6.0
55
Tested up to: 6.4
66
Requires PHP: 7.4
7-
Stable Tag: 2.1.2
7+
Stable Tag: 2.2.0
88
License: GPL-3
99
License URI: https://www.gnu.org/licenses/gpl-3.0.html
1010

@@ -116,6 +116,18 @@ This release is a complete re-architecture of WPGraphQL for ACF, introducing bre
116116

117117
== Changelog ==
118118

119+
= 2.2.0 =
120+
121+
**New Features**
122+
123+
- [#181](https://github.com/wp-graphql/wpgraphql-acf/pull/181): feat: update docs Date fields to link to the RFC3339 spec
124+
125+
**Chores / Bugfixes**
126+
127+
- [#182](https://github.com/wp-graphql/wpgraphql-acf/pull/182): fix: admin_enqueue_scripts callback should expect a possible null value passed to it
128+
- [#185](https://github.com/wp-graphql/wpgraphql-acf/pull/185): fix: clone field within a group field type returns null values
129+
- [#189](https://github.com/wp-graphql/wpgraphql-acf/pull/189): fix: image fields (and other connection fields) not properly resolving when queried asPreview
130+
119131
= 2.1.2 =
120132

121133
**Chores / Bugfixes**

src/Admin/PostTypeRegistration.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,18 @@ public function add_cpt_registration_fields( array $args, array $post_type ): ar
167167
}
168168

169169
/**
170-
* @param string $screen
170+
* Enqueue the admin scripts for the ACF Post Type settings.
171+
* This script is only enqueued on the ACF Post Type edit screen.
172+
*
173+
* @param ?string $screen
171174
*/
172-
public function enqueue_admin_scripts( string $screen ): void {
175+
public function enqueue_admin_scripts( ?string $screen ): void {
173176
global $post;
174177

178+
if ( empty( $screen ) ) {
179+
return;
180+
}
181+
175182
// if the screen is not a new post / edit post screen, do nothing
176183
if ( ! ( 'post-new.php' === $screen || 'post.php' === $screen ) ) {
177184
return;

src/Admin/TaxonomyRegistration.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,18 @@ public function add_taxonomy_registration_fields( array $args, array $taxonomy )
165165
}
166166

167167
/**
168-
* @param string $screen
168+
* Enqueue the admin scripts for the ACF Post Type settings.
169+
* This script is only enqueued on the ACF Taxonomy edit screen.
170+
*
171+
* @param ?string $screen
169172
*/
170-
public function enqueue_admin_scripts( string $screen ): void {
173+
public function enqueue_admin_scripts( ?string $screen ): void {
171174
global $post;
172175

176+
if ( empty( $screen ) ) {
177+
return;
178+
}
179+
173180
// if the screen is not a new post / edit post screen, do nothing
174181
if ( ! ( 'post-new.php' === $screen || 'post.php' === $screen ) ) {
175182
return;

src/FieldConfig.php

Lines changed: 21 additions & 3 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,14 @@ public function get_field_description(): string {
153156
);
154157
}
155158

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

@@ -234,6 +245,7 @@ public function get_graphql_field_config(): ?array {
234245
// bail and let the connection handle registration to the schema
235246
// and resolution
236247
if ( 'connection' === $field_type ) {
248+
$this->registry->register_field( $this->acf_field );
237249
return null;
238250
}
239251

@@ -390,11 +402,17 @@ public function resolve_field( $root, array $args, AppContext $context, ResolveI
390402

391403
// If the root being passed down already has a value
392404
// for the field key, let's use it to resolve
393-
if ( ! empty( $root[ $field_key ] ) ) {
394-
return $this->prepare_acf_field_value( $root[ $field_key ], $node, $node_id, $field_config );
405+
if ( isset( $field_config['key'] ) && ! empty( $root[ $field_config['key'] ] ) ) {
406+
return $this->prepare_acf_field_value( $root[ $field_config['key'] ], $node, $node_id, $field_config );
407+
}
408+
409+
// Check if the cloned field key is being used to pass values down
410+
if ( isset( $field_config['__key'] ) && ! empty( $root[ $field_config['__key'] ] ) ) {
411+
return $this->prepare_acf_field_value( $root[ $field_config['__key'] ], $node, $node_id, $field_config );
395412
}
396413

397-
if ( ! empty( $root[ $field_config['name'] ] ) ) {
414+
// Else check if the values are being passed down via the name
415+
if ( isset( $field_config['name'] ) && ! empty( $root[ $field_config['name'] ] ) ) {
398416
return $this->prepare_acf_field_value( $root[ $field_config['name'] ], $node, $node_id, $field_config );
399417
}
400418

src/FieldType/DatePicker.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,16 @@ public static function register_field_type(): void {
1212
register_graphql_acf_field_type(
1313
'date_picker',
1414
[
15-
'graphql_type' => 'String',
16-
'resolve' => static function ( $root, $args, $context, $info, $field_type, FieldConfig $field_config ) {
15+
'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' => static function ( FieldConfig $field_config ) {
19+
$field_type = $field_config->get_acf_field()['type'] ?? null;
20+
21+
// translators: The $s is the name of the acf field type that is returning a date string according to the RFC3339 spec.
22+
return '(' . sprintf( __( 'ACF Fields of the %s type return a date string according to the RFC3339 spec: https://datatracker.ietf.org/doc/html/rfc3339.', 'wpgraphql-acf' ), $field_type ) . ')';
23+
},
24+
'resolve' => static function ( $root, $args, $context, $info, $field_type, FieldConfig $field_config ) {
1725
$value = $field_config->resolve_field( $root, $args, $context, $info );
1826

1927
if ( empty( $value ) ) {

src/FieldType/DateTimePicker.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,16 @@ public static function register_field_type(): void {
1313
register_graphql_acf_field_type(
1414
'date_time_picker',
1515
[
16-
'graphql_type' => 'String',
17-
'resolve' => static function ( $root, $args, $context, $info, $field_type, FieldConfig $field_config ) {
16+
'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' => static function ( FieldConfig $field_config ) {
20+
$field_type = $field_config->get_acf_field()['type'] ?? null;
21+
22+
// translators: The $s is the name of the acf field type that is returning a date string according to the RFC3339 spec.
23+
return '(' . sprintf( __( 'ACF Fields of the "%s" type return a date string according to the RFC3339 spec: https://datatracker.ietf.org/doc/html/rfc3339.', 'wpgraphql-acf' ), $field_type ) . ')';
24+
},
25+
'resolve' => static function ( $root, $args, $context, $info, $field_type, FieldConfig $field_config ) {
1826
$value = $field_config->resolve_field( $root, $args, $context, $info );
1927

2028
if ( empty( $value ) ) {

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/Registry.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ public function get_registered_fields() {
6565
return $this->registered_fields;
6666
}
6767

68+
/**
69+
* @param array<mixed> $acf_field
70+
*
71+
* @return void
72+
*/
73+
public function register_field( $acf_field ) {
74+
75+
if ( isset( $acf_field['name'] ) && ! in_array( $acf_field['name'], $this->registered_fields, true ) ) {
76+
$this->registered_fields[] = $acf_field['name'];
77+
}
78+
79+
if ( isset( $acf_field['key'] ) && ! in_array( $acf_field['key'], $this->registered_fields, true ) ) {
80+
$this->registered_fields[] = $acf_field['key'];
81+
}
82+
}
83+
6884
/**
6985
* Get the TypeRegistry instance
7086
*/
@@ -505,11 +521,8 @@ public function map_acf_field_to_graphql( array $acf_field, array $acf_field_gro
505521
$field_config = ( new FieldConfig( $acf_field, $acf_field_group, $this ) )->get_graphql_field_config();
506522

507523
if ( ! empty( $field_config['acf_field'] ) ) {
508-
if ( isset( $field_config['acf_field']['key'] ) && ! in_array( $field_config['acf_field']['key'], $this->registered_fields, true ) ) {
509-
$this->registered_fields[] = $field_config['acf_field']['key'];
510-
}
511-
if ( isset( $field_config['acf_field']['name'] ) && ! in_array( $field_config['acf_field']['name'], $this->registered_fields, true ) ) {
512-
$this->registered_fields[] = $field_config['acf_field']['name'];
524+
if ( isset( $field_config['acf_field'] ) ) {
525+
$this->register_field( $field_config['acf_field'] );
513526
}
514527
}
515528

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)