Skip to content

Commit 90a4fc1

Browse files
authored
Merge pull request #100 from wp-graphql/fix/#96-bug-with-cptui-imports
fix: bug with CPTUI imports
2 parents 15b15a1 + da4a418 commit 90a4fc1

File tree

11 files changed

+104
-89
lines changed

11 files changed

+104
-89
lines changed

composer.lock

Lines changed: 35 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Admin/PostTypeRegistration.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public function init(): void {
2929
// this is a polyfill for tests to pass
3030
add_filter( 'acf/post_type_args', [ $this, 'add_cpt_registration_fields' ], 10, 2 );
3131

32-
3332
// Add tha GraphQL Tab to the ACF Post Type registration screen
3433
add_filter( 'acf/post_type/additional_settings_tabs', [ $this, 'add_tabs' ] );
3534

@@ -138,11 +137,13 @@ public function render_settings_tab( array $acf_post_type ): void {
138137
public function add_cpt_registration_fields( array $args, array $post_type ): array {
139138

140139
// respect the show_in_graphql value. If not set, use the value of $args['public'] to determine if the post type should be shown in graphql
141-
$args['show_in_graphql'] = isset( $args['show_in_graphql'] ) ? (bool) $args['show_in_graphql'] : true === $args['public'];
140+
$args['show_in_graphql'] = isset( $post_type['show_in_graphql'] ) ? (bool) $post_type['show_in_graphql'] : true === $args['public'];
142141

143142
$graphql_single_name = '';
144143

145-
if ( isset( $args['graphql_single_name'] ) ) {
144+
if ( isset( $post_type['graphql_single_name'] ) ) {
145+
$graphql_single_name = $post_type['graphql_single_name'];
146+
} elseif ( isset( $args['graphql_single_name'] ) ) {
146147
$graphql_single_name = $args['graphql_single_name'];
147148
} elseif ( isset( $args['labels']['singular_name'] ) ) {
148149
$graphql_single_name = Utils::format_field_name( $args['labels']['singular_name'], true );
@@ -153,7 +154,9 @@ public function add_cpt_registration_fields( array $args, array $post_type ): ar
153154

154155
$graphql_plural_name = '';
155156

156-
if ( isset( $args['graphql_plural_name'] ) ) {
157+
if ( isset( $post_type['graphql_plural_name'] ) ) {
158+
$graphql_plural_name = $post_type['graphql_plural_name'];
159+
} elseif ( isset( $args['graphql_plural_name'] ) ) {
157160
$graphql_plural_name = $args['graphql_plural_name'];
158161
} elseif ( isset( $args['labels']['name'] ) ) {
159162
$graphql_plural_name = Utils::format_field_name( $args['labels']['name'], true );

src/Admin/TaxonomyRegistration.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,13 @@ public function render_settings_tab( array $acf_taxonomy ): void {
135135
public function add_taxonomy_registration_fields( array $args, array $taxonomy ): array {
136136

137137
// respect the show_in_graphql value. If not set, use the value of $args['public'] to determine if the post type should be shown in graphql
138-
$args['show_in_graphql'] = isset( $args['show_in_graphql'] ) ? (bool) $args['show_in_graphql'] : true === $args['public'];
138+
$args['show_in_graphql'] = isset( $taxonomy['show_in_graphql'] ) ? (bool) $taxonomy['show_in_graphql'] : true === $args['public'];
139139

140140
$graphql_single_name = '';
141141

142-
if ( isset( $args['graphql_single_name'] ) ) {
142+
if ( isset( $taxonomy['graphql_single_name'] ) ) {
143+
$graphql_single_name = $taxonomy['graphql_single_name'];
144+
} elseif ( isset( $args['graphql_single_name'] ) ) {
143145
$graphql_single_name = $args['graphql_single_name'];
144146
} elseif ( isset( $args['labels']['singular_name'] ) ) {
145147
$graphql_single_name = Utils::format_field_name( $args['labels']['singular_name'], true );
@@ -150,7 +152,9 @@ public function add_taxonomy_registration_fields( array $args, array $taxonomy )
150152

151153
$graphql_plural_name = '';
152154

153-
if ( isset( $args['graphql_plural_name'] ) ) {
155+
if ( isset( $taxonomy['graphql_plural_name'] ) ) {
156+
$graphql_plural_name = $taxonomy['graphql_plural_name'];
157+
} elseif ( isset( $args['graphql_plural_name'] ) ) {
154158
$graphql_plural_name = $args['graphql_plural_name'];
155159
} elseif ( isset( $args['labels']['name'] ) ) {
156160
$graphql_plural_name = Utils::format_field_name( $args['labels']['name'], true );

src/FieldConfig.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,10 @@ public function resolve_field( $root, array $args, AppContext $context, ResolveI
381381
// resolve block field
382382
if ( is_array( $node ) && isset( $node['blockName'] ) ) {
383383
if ( isset( $node['attrs']['data'] ) ) {
384-
acf_setup_meta( $node['attrs']['data'], acf_get_block_id( $node['attrs']['data'] ), true );
384+
$block_id = acf_get_block_id( $node['attrs']['data'] );
385+
acf_setup_meta( $node['attrs']['data'], $block_id, true );
385386
acf_prepare_block( $node['attrs'] );
386-
$return_value = get_field( $field_config['name'] );
387+
$return_value = get_field( $field_config['name'], $block_id, $should_format_value );
387388

388389
if ( empty( $return_value ) && isset( $node['attrs']['data'][ $field_config['name'] ] ) ) {
389390
$return_value = $node['attrs']['data'][ $field_config['name'] ];

src/FieldType/Relationship.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static function register_field_type():void {
3030
static function ( $id ) {
3131
return absint( $id );
3232
},
33-
$value
33+
$value
3434
);
3535

3636
$resolver = new PostObjectConnectionResolver( $root, $args, $context, $info, 'any' );

src/FieldType/Repeater.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public static function register_field_type(): void {
2323
$sub_field_group['graphql_type_name'] = $type_name;
2424
$sub_field_group['graphql_field_name'] = $type_name;
2525

26-
2726
$field_config->get_registry()->register_acf_field_groups_to_graphql(
2827
[
2928
$sub_field_group,

tests/_support/WPUnit/AcfFieldTestCase.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,15 @@ interfaces {
298298
$this->markTestIncomplete( 'No block data to store defined' );
299299
}
300300

301+
$extra_data = $this->get_extra_block_data_to_store( $acf_field_key, $this->get_field_name() );
301302

303+
$extra_data = ( ! empty( $extra_data ) ) ? $extra_data : [];
302304
$encoded_block_data = wp_json_encode( [
303305
'name' => "acf/test-block",
304-
'data' => array_merge( [
306+
'data' => array_merge( $extra_data, [
305307
$this->get_field_name() => $this->get_block_data_to_store(),
306308
'_' . $this->get_field_name() => $acf_field_key,
307-
], $this->get_extra_block_data_to_store( $acf_field_key, $this->get_field_name() ) ),
309+
] ),
308310
'align' => '',
309311
'mode' => 'edit'
310312
] );
@@ -319,8 +321,7 @@ interfaces {
319321

320322
codecept_debug( [ 'html_block_content' => $content ]);
321323

322-
323-
$post = $this->factory()->post->create([
324+
$post = self::factory()->post->create([
324325
'post_type' => 'post',
325326
'post_status' => 'publish',
326327
'post_author' => $this->admin,
@@ -370,7 +371,7 @@ interfaces {
370371
])
371372
] );
372373

373-
374+
wp_delete_post( $post, true );
374375

375376
}
376377

tests/_support/WPUnit/WPGraphQLAcfTestCase.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,11 @@ public function remove_acf_field_groups(): void {
252252
*/
253253
public function register_acf_field_group( array $acf_field_group = [] ) {
254254

255+
$field_group_key = $acf_field_group['key'] ?? $this->get_acf_field_group_key();
256+
255257
// merge the defaults with the passed in options
256258
$config = array_merge( [
257-
'key' => $this->get_acf_field_group_key(),
259+
'key' => $field_group_key,
258260
'title' => 'ACF Test Group',
259261
'fields' => [],
260262
'location' => [
@@ -294,7 +296,7 @@ public function register_acf_field( array $acf_field = [], array $acf_field_grou
294296

295297

296298
$field_group_key = $this->register_acf_field_group( $acf_field_group );
297-
$key = $acf_field['key'] ?? uniqid( 'acf_test',true );
299+
$key = $acf_field['key'] ?? uniqid( 'acf_test', true );
298300

299301
$config = array_merge( [
300302
'parent' => $field_group_key,

tests/functional/CustomPostTypeRegistrationCest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ public function testPostTypeCanBeRegisteredToShowInGraphql( FunctionalTester $I
8585
$I->click( 'Generate PHP' );
8686
$I->seeElement( '//textarea[@id="acf-export-textarea"]');
8787
$I->see( "'show_in_graphql' => true", '//textarea[@id="acf-export-textarea"]');
88-
$I->see( "'graphql_single_name' => 'testType'", '//textarea[@id="acf-export-textarea"]');
89-
$I->see( "'graphql_plural_name' => 'testTypes'", '//textarea[@id="acf-export-textarea"]');
88+
$I->see( "'graphql_single_name' => 'testSingleName'", '//textarea[@id="acf-export-textarea"]');
89+
$I->see( "'graphql_plural_name' => 'testPluralName'", '//textarea[@id="acf-export-textarea"]');
9090

9191
}
9292

tests/functional/CustomTaxonomyRegistrationCest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ public function testTaxonomyCanBeRegisteredToShowInGraphql( FunctionalTester $I
8686
$I->click( 'Generate PHP' );
8787
$I->seeElement( '//textarea[@id="acf-export-textarea"]');
8888
$I->see( "'show_in_graphql' => true", '//textarea[@id="acf-export-textarea"]');
89-
$I->see( "'graphql_single_name' => 'testType'", '//textarea[@id="acf-export-textarea"]');
90-
$I->see( "'graphql_plural_name' => 'testTypes'", '//textarea[@id="acf-export-textarea"]');
89+
$I->see( "'graphql_single_name' => 'testSingleName'", '//textarea[@id="acf-export-textarea"]');
90+
$I->see( "'graphql_plural_name' => 'testPluralName'", '//textarea[@id="acf-export-textarea"]');
9191

9292
}
9393

0 commit comments

Comments
 (0)