Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #335 from wp-graphql/release/v0.6.0
Browse files Browse the repository at this point in the history
Release/v0.6.0
  • Loading branch information
jasonbahl authored Sep 15, 2022
2 parents 0ac0529 + a01a329 commit ee09e2f
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 55 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Setting the value of this field to "Yes" will show the field group in the WPGrap

When registering ACF Fields in PHP, you need to add `show_in_graphql` and `graphql_field_name` when defining your field group. See below as an example.

```
```php
function my_acf_add_local_field_groups() {

acf_add_local_field_group(array(
Expand Down
36 changes: 2 additions & 34 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: https://wpgraphql.com/acf
Tags: WPGraphQL, GraphQL, API, Advanced Custom Fields, ACF
Requires at least: 5.0
Tested up to: 5.1.1
Stable tag: 0.5.3
Stable tag: 0.6.0
License: GPL-3
License URI: https://www.gnu.org/licenses/gpl-3.0.html

Expand All @@ -17,39 +17,7 @@ allowing for interacting with ACF field data using GraphQL Queries.

== Changelog ==

= 0.1.7 =
* Add support for User Edit and User Register form locations

= 0.1.6 =
* Add support for Single Post / Page location rule for ACF Field Groups
* Fix bug with WYSIWYG field nested within repeaters/flex fields not properly getting wpautop applied
* Fix bug where Relationship fields were throwing errors when an item in the relationship had been deleted. Now the items are not included in the response at all and no errors are thrown

= 0.1.5 =
* Fix bug where field groups would disappear when using acf-local-json

= 0.1.4 =
* Fixes bug with WYSIWYG fields nested in Flex Fields and Repeater Fields not properly resolving
* Adds support for assigning ACF Field Groups to attachments (MediaItems)

= 0.1.3 =

* Adds support for the following locations: Menus, Menu Items, Taxonomies, Comments
* Fixed a bug where the "show_in_graphql" button wasn't showing on Radio Buttons

= 0.1.2 =
* Fixes bug with Nested Fields not properly showing in the Schema. By defualt, fields are not supposed
to be exposed in the Schema if they are not set to "show_in_graphql", however there was a flaw in
logic causing nested fields of Flex Field layouts to not properly be exposed to the Schema. This
fixes that issue, so nested fields of Flex Field layouts can properly be queried and seen in the
Schema.

= 0.1.1 =
* Fixes bug with Field groups not properly being exposed to the Schema for custom post types.

= 0.1.0 =
* Initial public release.

SEE: https://github.com/wp-graphql/wp-graphql-acf/releases

== Upgrade Notice ==

Expand Down
32 changes: 23 additions & 9 deletions src/class-acfsettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
*/
class ACF_Settings {

protected $is_acf6_or_higher = false;

/**
* Initialize ACF Settings for the plugin
*/
public function init() {

$this->is_acf6_or_higher = defined( 'ACF_MAJOR_VERSION' ) && version_compare( ACF_MAJOR_VERSION, 6, '>=' );

/**
* Add settings to individual fields to allow each field granular control
* over how it's shown in the GraphQL Schema
Expand Down Expand Up @@ -110,7 +114,10 @@ public function display_metabox( $field_group_post_object ) {
'prefix' => 'acf_field_group',
'value' => isset( $field_group['show_in_graphql'] ) ? (bool) $field_group['show_in_graphql'] : false,
'ui' => 1,
]
],
'div',
'label',
true
);

/**
Expand All @@ -126,7 +133,10 @@ public function display_metabox( $field_group_post_object ) {
'required' => isset( $field_group['show_in_graphql'] ) ? (bool) $field_group['show_in_graphql'] : false,
'placeholder' => ! empty( $field_group['graphql_field_name'] ) ? $field_group['graphql_field_name'] : null,
'value' => ! empty( $field_group['graphql_field_name'] ) ? $field_group['graphql_field_name'] : null,
]
],
'div',
'label',
true
);

acf_render_field_wrap(
Expand All @@ -138,7 +148,10 @@ public function display_metabox( $field_group_post_object ) {
'prefix' => 'acf_field_group',
'value' => isset( $field_group['map_graphql_types_from_location_rules'] ) ? (bool) $field_group['map_graphql_types_from_location_rules'] : false,
'ui' => 1,
]
],
'div',
'label',
true
);

$choices = Config::get_all_graphql_types();
Expand All @@ -152,7 +165,10 @@ public function display_metabox( $field_group_post_object ) {
'value' => ! empty( $field_group['graphql_types'] ) ? $field_group['graphql_types'] : [],
'toggle' => true,
'choices' => $choices,
]
],
'div',
'label',
true
);

?>
Expand All @@ -164,7 +180,7 @@ public function display_metabox( $field_group_post_object ) {
if (typeof acf !== 'undefined') {
acf.newPostbox({
'id': 'wpgraphql-acf-meta-box',
'label': 'left'
'label': <?php echo $this->is_acf6_or_higher ? 'top' : "'left'"; ?>
});
}
</script>
Expand Down Expand Up @@ -217,14 +233,12 @@ public function add_field_settings( array $field ) {
public function enqueue_graphql_acf_scripts( string $screen ) {
global $post;

if ( $screen == 'post-new.php' || $screen == 'post.php' ) {
if ( 'acf-field-group' === $post->post_type ) {
wp_enqueue_script( 'graphql-acf', plugins_url( 'src/js/main.js', dirname( __FILE__ ) ), array(
if ( ( $screen === 'post-new.php' || $screen === 'post.php' ) && ( isset( $post->post_type ) && 'acf-field-group' === $post->post_type ) ) {
wp_enqueue_script( 'graphql-acf', plugins_url( 'src/js/main.js', __DIR__ ), array(
'jquery',
'acf-input',
'acf-field-group'
) );
}
}
}

Expand Down
19 changes: 15 additions & 4 deletions src/class-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,15 @@ protected function get_acf_field_value( $root, $acf_field, $format = false ) {

}

/**
* Filters the returned ACF field value using acf filters
*
* @param mixed $value The resolved ACF field value
* @param int $id The ID of the object
* @param array $acf_field The ACF field config
*/
$value = apply_filters('acf/format_value', $value, $id, $acf_field);

/**
* Filters the returned ACF field value
*
Expand Down Expand Up @@ -636,7 +645,7 @@ protected function register_graphql_field( string $type_name, string $field_name
$value = $this->get_acf_field_value( $root, $acf_field, true );

if ( ! empty( $value ) && ! empty( $acf_field['return_format'] ) ) {
$value = date( $acf_field['return_format'], strtotime( $value ) );
$value = date_i18n( $acf_field['return_format'], strtotime( $value ) );
}
return ! empty( $value ) ? $value : null;
},
Expand Down Expand Up @@ -689,12 +698,14 @@ protected function register_graphql_field( string $type_name, string $field_name
$post_object = get_post( $post_id );
if ( $post_object instanceof \WP_Post ) {
$post_model = new Post( $post_object );
$relationship[] = $post_model;
if ( 'private' != $post_model->get_visibility() ) {
$relationship[] = $post_model;
}
}
}
}

return isset( $value ) ? $relationship : null;
return empty( $relationship ) ? null : $relationship;

},
];
Expand Down Expand Up @@ -1340,7 +1351,7 @@ public static function get_all_graphql_types() {
$graphql_types[ $interface_name ] = '<span data-interface="'. $interface_name .'">' . $interface_name . ' Interface (' . $config['plural_label'] . ')</span>';
$label = '<span data-implements="'. $interface_name .'"> (' . $config['label'] . ')</span>';
foreach ( $possible_types as $type ) {
$type_label = $type['name'] . $label;
$type_label = $type['name'] . '&nbsp;' . $label;
$type_key = $type['name'];

$graphql_types[ $type_key ] = $type_label;
Expand Down
11 changes: 10 additions & 1 deletion src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,16 @@ $j(document).ready(function () {
*/
function setGraphqlFieldName() {
var graphqlFieldNameField = $j('#acf_field_group-graphql_field_name');
var fieldGroupTitle = $j('#titlediv #title');

// support for v6+
if ( $j('#title.acf-headerbar-title-field').exists() ) {
var fieldGroupTitle = $j('#title.acf-headerbar-title-field');

// versions of ACF < v6
} else {
var fieldGroupTitle = $j('#titlediv #title');
}

if ('' === graphqlFieldNameField.val()) {
graphqlFieldNameField.val(formatFieldName(fieldGroupTitle.val()));
}
Expand Down
2 changes: 1 addition & 1 deletion src/location-rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function check_for_conflicts( array $and_params, $param, $allowed_params
*
* @return bool
*/
public function check_params_for_conflicts( array $and_params = [], $param ) {
public function check_params_for_conflicts( array $and_params = [], string $param = '' ) {
switch ( $param ) {
case 'post_type':
$allowed_and_params = [
Expand Down
3 changes: 2 additions & 1 deletion tests/wpunit/ExplicitOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public function testExplicitOptions() {
'show_in_graphql' => true,
'graphql_single_name' => 'acfCpt',
'graphql_plural_name' => 'acfCpts',
'public' => true,
]
);

Expand Down Expand Up @@ -148,7 +149,7 @@ public function testExplicitOptions() {
]
);

$expected_text_3 = 'test value2';
$expected_text_3 = 'test value3';
update_field( 'acf_text_field', $expected_text_3, $cpt_id );

// post assert validation.
Expand Down
4 changes: 2 additions & 2 deletions tests/wpunit/PostObjectFieldsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1213,8 +1213,8 @@ public function testQueryMultipleSelectFieldWithNoValueSet() {
public function testQueryFieldOnCustomPostType() {

register_post_type( 'acf_test', [
'show_ui' => true,
'show_in_graphql' => 'true',
'public' => true,
'show_in_graphql' => 'true',
'graphql_single_name' => 'acfTest',
'graphql_plural_name' => 'acfTests'
] );
Expand Down
4 changes: 2 additions & 2 deletions wp-graphql-acf.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Author URI: https://www.wpgraphql.com
* Text Domain: wp-graphql-acf
* Domain Path: /languages
* Version: 0.5.3
* Version: 0.6.0
* Requires PHP: 7.0
* GitHub Plugin URI: https://github.com/wp-graphql/wp-graphql-acf
*
Expand All @@ -26,7 +26,7 @@
* Define constants
*/
const WPGRAPHQL_REQUIRED_MIN_VERSION = '0.4.0';
const WPGRAPHQL_ACF_VERSION = '0.5.3';
const WPGRAPHQL_ACF_VERSION = '0.6.0';

/**
* Initialize the plugin
Expand Down

0 comments on commit ee09e2f

Please sign in to comment.