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

Fix #135. Add Explicit options for adding ACF Field Groups to the Schema #229

Merged
merged 24 commits into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6cb6193
Fix #135. Add Explicit options for adding ACF Field Groups to the Schema
rsm0128 Jan 19, 2021
46696e3
Fixed formatting issues. Reverted phpcs auto formatting error and fol…
rsm0128 Jan 19, 2021
fc010f7
fixed spelling issue. Thanks @drewbaker
rsm0128 Jan 23, 2021
3c9349b
updated unit test with new graphql_types_on field
rsm0128 Mar 15, 2021
1271ed9
Aded Explicit Options WpUnit test case
rsm0128 Mar 15, 2021
36b03c0
updated plugin version check
rsm0128 Mar 15, 2021
629dfac
fixed typo issue with user register fields
rsm0128 Mar 20, 2021
078cc98
Added contentNode and termNode support for the explicit option
rsm0128 Mar 20, 2021
7f1ebdd
- add plaftform_check to .gitignore
jasonbahl Mar 20, 2021
f51d294
- Update GraphQL Settings fields to use the GraphQL Type names as val…
jasonbahl Mar 31, 2021
0d2e191
- Add the `ContentTemplate` interface to the Checkboxes
jasonbahl Mar 31, 2021
c6e3888
- Fix typo in JS for unsetting checked state
jasonbahl Mar 31, 2021
8f56a30
- add filter to `ContentTemplate` fields to pass the source node alon…
jasonbahl Apr 5, 2021
6ef9cc1
- removes activation script that tries to upgrade location rules
jasonbahl Apr 6, 2021
b202db1
- Update test to include nav menu registration
jasonbahl Apr 6, 2021
d7cb493
- Update test message linking to WPGraphQL Issue
jasonbahl Apr 6, 2021
21a0b8f
- Update ACF Settings tp include an AJAX action/callback for determin…
jasonbahl Apr 9, 2021
63afa2f
Merge commit '3bf411f270c591a89dce3b41acb655046139a10e' into bugfix-135
jasonbahl Apr 9, 2021
4ed2017
- Move GraphQL Field Group Settings into their own box in the ACF Fie…
jasonbahl Apr 12, 2021
faa5701
- remove dummy code from wp-graphql-acf
jasonbahl Apr 14, 2021
8bde1b2
- update testing matrix
jasonbahl Apr 14, 2021
e35e895
- update testing matrix
jasonbahl Apr 14, 2021
d0ca31f
- Update tests to test with multiple versions of WPGraphQL
jasonbahl Apr 14, 2021
bf4c781
- Update .gitignore to not ignore the platform check
jasonbahl Apr 20, 2021
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
Next Next commit
Fix #135. Add Explicit options for adding ACF Field Groups to the Schema
  • Loading branch information
rsm0128 committed Mar 13, 2021
commit 6cb6193363dcce54c3fb830dfc10e69297b27edd
35 changes: 12 additions & 23 deletions src/class-acf.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* ACF
*
Expand Down Expand Up @@ -27,7 +28,7 @@ final class ACF {
*/
public static function instance() {

if ( ! isset( self::$instance ) && ! ( self::$instance instanceof ACF ) ) {
if (!isset(self::$instance) && !(self::$instance instanceof ACF)) {
self::$instance = new ACF();
self::$instance->setup_constants();
self::$instance->includes();
Expand All @@ -41,7 +42,7 @@ public static function instance() {
*
* @param ACF $instance The instance of the WPGraphQL\ACF class
*/
do_action( 'graphql_acf_init', self::$instance );
do_action('graphql_acf_init', self::$instance);

/**
* Return the WPGraphQL Instance
Expand All @@ -60,8 +61,7 @@ public static function instance() {
public function __clone() {

// Cloning instances of the class is forbidden.
_doing_it_wrong( __FUNCTION__, esc_html__( 'The \WPGraphQL\ACF class should not be cloned.', 'wp-graphql-acf' ), '0.0.1' );

_doing_it_wrong(__FUNCTION__, esc_html__('The \WPGraphQL\ACF class should not be cloned.', 'wp-graphql-acf'), '0.0.1');
}

/**
Expand All @@ -73,8 +73,7 @@ public function __clone() {
public function __wakeup() {

// De-serializing instances of the class is forbidden.
_doing_it_wrong( __FUNCTION__, esc_html__( 'De-serializing instances of the \WPGraphQL\ACF class is not allowed', 'wp-graphql-acf' ), '0.0.1' );

_doing_it_wrong(__FUNCTION__, esc_html__('De-serializing instances of the \WPGraphQL\ACF class is not allowed', 'wp-graphql-acf'), '0.0.1');
}

/**
Expand All @@ -85,26 +84,20 @@ public function __wakeup() {
*/
private function setup_constants() {

// Plugin version.
if ( ! defined( 'WPGRAPHQL_ACF_VERSION' ) ) {
define( 'WPGRAPHQL_ACF_VERSION', '0.3.0' );
}

// Plugin Folder Path.
if ( ! defined( 'WPGRAPHQL_ACF_PLUGIN_DIR' ) ) {
define( 'WPGRAPHQL_ACF_PLUGIN_DIR', plugin_dir_path( __FILE__ . '/..' ) );
if (!defined('WPGRAPHQL_ACF_PLUGIN_DIR')) {
define('WPGRAPHQL_ACF_PLUGIN_DIR', plugin_dir_path(__FILE__ . '/..'));
}

// Plugin Folder URL.
if ( ! defined( 'WPGRAPHQL_ACF_PLUGIN_URL' ) ) {
define( 'WPGRAPHQL_ACF_PLUGIN_URL', plugin_dir_url( __FILE__ . '/..' ) );
if (!defined('WPGRAPHQL_ACF_PLUGIN_URL')) {
define('WPGRAPHQL_ACF_PLUGIN_URL', plugin_dir_url(__FILE__ . '/..'));
}

// Plugin Root File.
if ( ! defined( 'WPGRAPHQL_ACF_PLUGIN_FILE' ) ) {
define( 'WPGRAPHQL_ACF_PLUGIN_FILE', __FILE__ . '/..' );
if (!defined('WPGRAPHQL_ACF_PLUGIN_FILE')) {
define('WPGRAPHQL_ACF_PLUGIN_FILE', __FILE__ . '/..');
}

}

/**
Expand All @@ -124,14 +117,12 @@ private function includes() {
* cycle
*/
private function actions() {

}

/**
* Setup filters
*/
private function filters() {

}

/**
Expand All @@ -140,11 +131,9 @@ private function filters() {
private function init() {

$config = new Config();
add_action( 'graphql_register_types', [ $config, 'init' ], 10, 1 );
add_action('graphql_register_types', [$config, 'init'], 10, 1);

$acf_settings = new ACF_Settings();
$acf_settings->init();

}

}
47 changes: 29 additions & 18 deletions src/class-acfsettings.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* ACF extension for WP-GraphQL
*
Expand All @@ -23,29 +24,28 @@ public function init() {
* Creates a field group setting to allow a field group to be
* shown in the GraphQL Schema.
*/
add_action( 'acf/render_field_group_settings', [ $this, 'add_field_group_settings' ], 10, 1 );
add_action('acf/render_field_group_settings', [$this, 'add_field_group_settings'], 10, 1);

/**
* Add settings to individual fields to allow each field granular control
* over how it's shown in the GraphQL Schema
*/
add_action( 'acf/render_field_settings', [ $this, 'add_field_settings' ], 10, 1 );

add_action('acf/render_field_settings', [$this, 'add_field_settings'], 10, 1);
}

/**
* Add settings to each field to show in GraphQL
*
* @param array $field The field to add the setting to.
*/
public function add_field_settings( $field ) {
public function add_field_settings($field) {

$supported_fields = Config::get_supported_fields();

/**
* If there are no supported fields, or the field is not supported, don't add a setting field.
*/
if ( empty( $supported_fields ) || ! is_array( $supported_fields ) || ! in_array( $field['type'], $supported_fields, true ) ) {
if (empty($supported_fields) || !is_array($supported_fields) || !in_array($field['type'], $supported_fields, true)) {
return;
}

Expand All @@ -55,17 +55,16 @@ public function add_field_settings( $field ) {
acf_render_field_setting(
$field,
[
'label' => __( 'Show in GraphQL', 'wp-graphql-acf' ),
'instructions' => __( 'Whether the field should be queryable via GraphQL', 'wp-graphql-acf' ),
'label' => __('Show in GraphQL', 'wp-graphql-acf'),
'instructions' => __('Whether the field should be queryable via GraphQL', 'wp-graphql-acf'),
'name' => 'show_in_graphql',
'type' => 'true_false',
'ui' => 1,
'default_value' => 1,
'value' => isset( $field['show_in_graphql'] ) ? (bool) $field['show_in_graphql'] : true,
'value' => isset($field['show_in_graphql']) ? (bool) $field['show_in_graphql'] : true,
],
true
);

}

/**
Expand All @@ -76,19 +75,19 @@ public function add_field_settings( $field ) {
*
* @param array $field_group The field group to add settings to.
*/
public function add_field_group_settings( $field_group ) {
public function add_field_group_settings($field_group) {

/**
* Render a field in the Field Group settings to allow for a Field Group to be shown in GraphQL.
*/
acf_render_field_wrap(
[
'label' => __( 'Show in GraphQL', 'acf' ),
'instructions' => __( 'If the field group is active, and this is set to show, the fields in this group will be available in the WPGraphQL Schema based on the respective Location rules.' ),
'label' => __('Show in GraphQL', 'acf'),
'instructions' => __('If the field group is active, and this is set to show, the fields in this group will be available in the WPGraphQL Schema based on the respective Location rules.'),
'type' => 'true_false',
'name' => 'show_in_graphql',
'prefix' => 'acf_field_group',
'value' => isset( $field_group['show_in_graphql'] ) ? (bool) $field_group['show_in_graphql'] : false,
'value' => isset($field_group['show_in_graphql']) ? (bool) $field_group['show_in_graphql'] : false,
'ui' => 1,
]
);
Expand All @@ -98,17 +97,29 @@ public function add_field_group_settings( $field_group ) {
*/
acf_render_field_wrap(
[
'label' => __( 'GraphQL Field Name', 'acf' ),
'instructions' => __( 'The name of the field group in the GraphQL Schema.', 'wp-graphql-acf' ),
'label' => __('GraphQL Field Name', 'acf'),
'instructions' => __('The name of the field group in the GraphQL Schema.', 'wp-graphql-acf'),
'type' => 'text',
'prefix' => 'acf_field_group',
'name' => 'graphql_field_name',
'required' => true,
'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,
'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,
]
);

$choices = Config::get_all_graphql_types();
acf_render_field_wrap(
[
'label' => __('GraphQL Types to Show the Field Group On', 'wp-graphql-acf'),
'instructions' => __('Select the Types in the WPGraphQl Schema to show the fields in this fiedl group on', 'wp-graphql-acf'),
'type' => 'checkbox',
'prefix' => 'acf_field_group',
'name' => 'graphql_types_on',
'value' => !empty($field_group['graphql_types_on']) ? $field_group['graphql_types_on'] : null,
'toggle' => true,
'choices' => $choices
]
);
}

}
Loading