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

Release/v0.6.0 #335

Merged
merged 22 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3ed252a
Update README.md
RodrigoTomeES Sep 10, 2021
53372ad
Use date_i18n() to set correct timezone for date time fields
esamattis Oct 20, 2021
56cd1d3
fix #300, #85, #100
rsm0128 Nov 10, 2021
61b16a6
updated unite test
rsm0128 Nov 10, 2021
164f2b3
Merge pull request #301 from rsm0128/bug/#300-relationship-error-post…
jasonbahl Nov 10, 2021
365951c
Merge pull request #299 from esamattis/timezone
jasonbahl Nov 10, 2021
4d054bd
Update to support true or false value instead of null
seripap Dec 3, 2021
e324aa2
filter returnes value with acf/format_value
Feb 15, 2022
f2828e4
Fix deprecated error
fedek6 Mar 7, 2022
dafccc4
Merge commit '0ac0529697d67192ce6b0e9fc27c5dfb3807250c' into develop
jasonbahl Jul 13, 2022
3140ca8
- add new render_field_wrap function to determine whether to use the …
jasonbahl Sep 15, 2022
6ce0160
- remove abstraction around `acf_render_field_wrap` as passing addit…
jasonbahl Sep 15, 2022
3659ed5
Merge pull request #333 from jasonbahl/feature/acf6-compat
jasonbahl Sep 15, 2022
5123c64
Merge pull request #313 from fedek6/develop
jasonbahl Sep 15, 2022
4a02e09
Merge pull request #309 from anacoelhovicente/bug/#192-acf-format-val…
jasonbahl Sep 15, 2022
cb00ecd
Merge pull request #304 from seripap/develop
jasonbahl Sep 15, 2022
dc329aa
Merge pull request #290 from RodrigoTomeES/patch-1
jasonbahl Sep 15, 2022
8444a4d
- update version, changelog
jasonbahl Sep 15, 2022
8b9bb24
- update changelog to point to releases (for now)
jasonbahl Sep 15, 2022
2bd4316
Revert "Returning false for true_false values"
jasonbahl Sep 15, 2022
4fb24c0
Merge pull request #334 from wp-graphql/revert-304-develop
jasonbahl Sep 15, 2022
a01a329
Merge commit '4fb24c0911ba5458a8585cc58f78ab503c468c65' into release/…
jasonbahl Sep 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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