From 20b0ec9fbb55a417e8b7f7312f4abcb029226a28 Mon Sep 17 00:00:00 2001 From: mistenkt Date: Thu, 20 Feb 2020 11:58:54 +0100 Subject: [PATCH] added support for advanced-custom-fields-table-field --- src/class-config.php | 62 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/src/class-config.php b/src/class-config.php index 6bcf71d..aa7e52f 100644 --- a/src/class-config.php +++ b/src/class-config.php @@ -320,7 +320,8 @@ public static function get_supported_fields() { 'color_picker', 'group', 'repeater', - 'flexible_content' + 'flexible_content', + 'table' ]; /** @@ -550,7 +551,7 @@ protected function register_graphql_field( $type_name, $field_name, $config ) { /** * This hooks allows for filtering of the post object source. In case an non-core defined * post-type is being targeted. - * + * * @param mixed|null $source GraphQL Type source. * @param mixed|null $value Root ACF field value. * @param AppContext $context AppContext instance. @@ -703,7 +704,7 @@ protected function register_graphql_field( $type_name, $field_name, $config ) { $field_config['type'] = $field_type_name; break; } - + $fields = [ 'streetAddress' => [ 'type' => 'String', @@ -938,6 +939,61 @@ protected function register_graphql_field( $type_name, $field_name, $config ) { }; } break; + case 'table': + $field_type_name = 'ACF_Table'; + + register_graphql_object_type( + 'ACF_Table_Row', + [ + 'fields' => [ + 'columns' => [ + 'type' => ['list_of' => 'String'], + 'resolve' => function($root) { + return $root; + } + ] + ] + ] + ); + + $fields = [ + 'useHeader' => [ + 'type' => 'Boolean', + 'resolve' => function($root) { + return $root['p']['o']['uh'] === 1; + } + ], + 'headers' => [ + 'type' => ['list_of' => 'String'], + 'resolve' => function($root) { + return !empty($root['h']) ? array_map(function($c) { + return $c['c']; + }, $root['h']) : []; + } + ], + 'rows' => [ + 'type' => ['list_of' => 'ACF_Table_Row'], + 'resolve' => function($root) { + return !empty($root['b']) ? array_map(function($r) { + return array_map(function($c) { + return $c['c']; + }, $r); + }, $root['b']) : []; + } + ] + + ]; + + register_graphql_object_type( + $field_type_name, + [ + 'description' => __('Table field', 'wp-graphql-acf'), + 'fields' => $fields + ] + ); + + $field_config['type'] = $field_type_name; + break; default: break; }