Skip to content

Commit

Permalink
Merge pull request #190 from wp-graphql/release/v2.2.0
Browse files Browse the repository at this point in the history
release: v2.2.0
  • Loading branch information
jasonbahl authored Mar 15, 2024
2 parents 5d500c0 + 43b778d commit 153761c
Show file tree
Hide file tree
Showing 17 changed files with 417 additions and 29 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## 2.2.0

## New Features

- [#181](https://github.com/wp-graphql/wpgraphql-acf/pull/181): feat: update docs Date fields to link to the RFC3339 spec

### Chores / Bugfixes

- [#182](https://github.com/wp-graphql/wpgraphql-acf/pull/182): fix: admin_enqueue_scripts callback should expect a possible null value passed to it
- [#185](https://github.com/wp-graphql/wpgraphql-acf/pull/185): fix: clone field within a group field type returns null values
- [#189](https://github.com/wp-graphql/wpgraphql-acf/pull/189): fix: image fields (and other connection fields) not properly resolving when queried asPreview

## 2.1.2

### Chores / Bugfixes
Expand Down
14 changes: 13 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: GraphQL, ACF, API, NextJS, Faust, Headless, Decoupled, React, Vue, Svelte,
Requires at least: 6.0
Tested up to: 6.4
Requires PHP: 7.4
Stable Tag: 2.1.2
Stable Tag: 2.2.0
License: GPL-3
License URI: https://www.gnu.org/licenses/gpl-3.0.html

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

== Changelog ==

= 2.2.0 =

**New Features**

- [#181](https://github.com/wp-graphql/wpgraphql-acf/pull/181): feat: update docs Date fields to link to the RFC3339 spec

**Chores / Bugfixes**

- [#182](https://github.com/wp-graphql/wpgraphql-acf/pull/182): fix: admin_enqueue_scripts callback should expect a possible null value passed to it
- [#185](https://github.com/wp-graphql/wpgraphql-acf/pull/185): fix: clone field within a group field type returns null values
- [#189](https://github.com/wp-graphql/wpgraphql-acf/pull/189): fix: image fields (and other connection fields) not properly resolving when queried asPreview

= 2.1.2 =

**Chores / Bugfixes**
Expand Down
11 changes: 9 additions & 2 deletions src/Admin/PostTypeRegistration.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,18 @@ public function add_cpt_registration_fields( array $args, array $post_type ): ar
}

/**
* @param string $screen
* Enqueue the admin scripts for the ACF Post Type settings.
* This script is only enqueued on the ACF Post Type edit screen.
*
* @param ?string $screen
*/
public function enqueue_admin_scripts( string $screen ): void {
public function enqueue_admin_scripts( ?string $screen ): void {
global $post;

if ( empty( $screen ) ) {
return;
}

// if the screen is not a new post / edit post screen, do nothing
if ( ! ( 'post-new.php' === $screen || 'post.php' === $screen ) ) {
return;
Expand Down
11 changes: 9 additions & 2 deletions src/Admin/TaxonomyRegistration.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,18 @@ public function add_taxonomy_registration_fields( array $args, array $taxonomy )
}

/**
* @param string $screen
* Enqueue the admin scripts for the ACF Post Type settings.
* This script is only enqueued on the ACF Taxonomy edit screen.
*
* @param ?string $screen
*/
public function enqueue_admin_scripts( string $screen ): void {
public function enqueue_admin_scripts( ?string $screen ): void {
global $post;

if ( empty( $screen ) ) {
return;
}

// if the screen is not a new post / edit post screen, do nothing
if ( ! ( 'post-new.php' === $screen || 'post.php' === $screen ) ) {
return;
Expand Down
24 changes: 21 additions & 3 deletions src/FieldConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ protected function is_supported_field_type(): bool {
*/
public function get_field_description(): string {

$graphql_field_type = $this->get_graphql_field_type();
$field_type_config = ( $graphql_field_type instanceof AcfGraphQLFieldType ) ? $graphql_field_type->get_config() : [];

// Use the explicit graphql_description, if set
if ( ! empty( $this->acf_field['graphql_description'] ) ) {
$description = $this->acf_field['graphql_description'];
Expand All @@ -153,6 +156,14 @@ public function get_field_description(): string {
);
}

if ( isset( $field_type_config['graphql_description_after'] ) ) {
if ( is_callable( $field_type_config['graphql_description_after'] ) ) {
$description .= ' ' . call_user_func( $field_type_config['graphql_description_after'], $this );
} else {
$description .= ' ' . $field_type_config['graphql_description_after'];
}
}

return $description;
}

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

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

// If the root being passed down already has a value
// for the field key, let's use it to resolve
if ( ! empty( $root[ $field_key ] ) ) {
return $this->prepare_acf_field_value( $root[ $field_key ], $node, $node_id, $field_config );
if ( isset( $field_config['key'] ) && ! empty( $root[ $field_config['key'] ] ) ) {
return $this->prepare_acf_field_value( $root[ $field_config['key'] ], $node, $node_id, $field_config );
}

// Check if the cloned field key is being used to pass values down
if ( isset( $field_config['__key'] ) && ! empty( $root[ $field_config['__key'] ] ) ) {
return $this->prepare_acf_field_value( $root[ $field_config['__key'] ], $node, $node_id, $field_config );
}

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

Expand Down
12 changes: 10 additions & 2 deletions src/FieldType/DatePicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ public static function register_field_type(): void {
register_graphql_acf_field_type(
'date_picker',
[
'graphql_type' => 'String',
'resolve' => static function ( $root, $args, $context, $info, $field_type, FieldConfig $field_config ) {
'graphql_type' => 'String',
// Apply a description to be appended to the field description.
// @todo: consider removing when CustomScalar types are supported along with the @specifiedBy directive
'graphql_description_after' => static function ( FieldConfig $field_config ) {
$field_type = $field_config->get_acf_field()['type'] ?? null;

// translators: The $s is the name of the acf field type that is returning a date string according to the RFC3339 spec.
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 ) . ')';
},
'resolve' => static function ( $root, $args, $context, $info, $field_type, FieldConfig $field_config ) {
$value = $field_config->resolve_field( $root, $args, $context, $info );

if ( empty( $value ) ) {
Expand Down
12 changes: 10 additions & 2 deletions src/FieldType/DateTimePicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@ public static function register_field_type(): void {
register_graphql_acf_field_type(
'date_time_picker',
[
'graphql_type' => 'String',
'resolve' => static function ( $root, $args, $context, $info, $field_type, FieldConfig $field_config ) {
'graphql_type' => 'String',
// Apply a description to be appended to the field description.
// @todo: consider removing when CustomScalar types are supported along with the @specifiedBy directive
'graphql_description_after' => static function ( FieldConfig $field_config ) {
$field_type = $field_config->get_acf_field()['type'] ?? null;

// translators: The $s is the name of the acf field type that is returning a date string according to the RFC3339 spec.
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 ) . ')';
},
'resolve' => static function ( $root, $args, $context, $info, $field_type, FieldConfig $field_config ) {
$value = $field_config->resolve_field( $root, $args, $context, $info );

if ( empty( $value ) ) {
Expand Down
4 changes: 3 additions & 1 deletion src/FieldType/FlexibleContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ static function ( $field ) use ( $layout ) {
)
);

$layout['sub_fields'] = array_merge( $sub_fields, $layout['sub_fields'] );
$layout_sub_fields = ! empty( $layout['sub_fields'] ) && is_array( $layout['sub_fields'] ) ? $layout['sub_fields'] : [];

$layout['sub_fields'] = array_merge( $sub_fields, $layout_sub_fields );

$layouts[] = $layout;
}
Expand Down
23 changes: 18 additions & 5 deletions src/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ public function get_registered_fields() {
return $this->registered_fields;
}

/**
* @param array<mixed> $acf_field
*
* @return void
*/
public function register_field( $acf_field ) {

if ( isset( $acf_field['name'] ) && ! in_array( $acf_field['name'], $this->registered_fields, true ) ) {
$this->registered_fields[] = $acf_field['name'];
}

if ( isset( $acf_field['key'] ) && ! in_array( $acf_field['key'], $this->registered_fields, true ) ) {
$this->registered_fields[] = $acf_field['key'];
}
}

/**
* Get the TypeRegistry instance
*/
Expand Down Expand Up @@ -505,11 +521,8 @@ public function map_acf_field_to_graphql( array $acf_field, array $acf_field_gro
$field_config = ( new FieldConfig( $acf_field, $acf_field_group, $this ) )->get_graphql_field_config();

if ( ! empty( $field_config['acf_field'] ) ) {
if ( isset( $field_config['acf_field']['key'] ) && ! in_array( $field_config['acf_field']['key'], $this->registered_fields, true ) ) {
$this->registered_fields[] = $field_config['acf_field']['key'];
}
if ( isset( $field_config['acf_field']['name'] ) && ! in_array( $field_config['acf_field']['name'], $this->registered_fields, true ) ) {
$this->registered_fields[] = $field_config['acf_field']['name'];
if ( isset( $field_config['acf_field'] ) ) {
$this->register_field( $field_config['acf_field'] );
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/ThirdParty/AcfExtended/AcfExtended.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,12 @@ public function register_initial_types(): void {
'startDate' => [
// @todo: DATETIME Scalar
'type' => 'String',
'description' => __( 'The start date of a date range returned as an RFC 3339 time string', 'wpgraphql-acf' ),
'description' => __( 'The start date of a date range returned as an RFC 3339 time string (https://datatracker.ietf.org/doc/html/rfc3339)', 'wpgraphql-acf' ),
],
'endDate' => [
// @todo: DATETIME Scalar
'type' => 'String',
'description' => __( 'The start date of a date range RFC 3339 time string', 'wpgraphql-acf' ),
'description' => __( 'The start date of a date range RFC 3339 time string (https://datatracker.ietf.org/doc/html/rfc3339)', 'wpgraphql-acf' ),
],
],
]
Expand Down
Binary file added tests/_data/images/test2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 153761c

Please sign in to comment.