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

added support for advanced-custom-fields-table-field #109

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
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
62 changes: 59 additions & 3 deletions src/class-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ public static function get_supported_fields() {
'color_picker',
'group',
'repeater',
'flexible_content'
'flexible_content',
'table'
];

/**
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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;
}
Expand Down