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

Commit

Permalink
Merge pull request #125 from jasonbahl/bug/#108-followup
Browse files Browse the repository at this point in the history
Bug/#108 followup
  • Loading branch information
jasonbahl authored Apr 17, 2020
2 parents b909b92 + e1aa095 commit 7d73316
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 26 deletions.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
"wpunit-test": "vendor/bin/codecept run wpunit"
},
"require-dev": {
"lucatume/wp-browser": ">=2.2.1 <2.2.8"
"lucatume/wp-browser": "^2.2.",
"dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
"wp-coding-standards/wpcs": "^2.1",
"phpcompatibility/phpcompatibility-wp": "^2.0"
}
}
22 changes: 9 additions & 13 deletions src/class-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,11 @@ protected function add_acf_fields_to_post_object_types() {
*
* @param [type] $root Undocumented.
* @param [type] $acf_field Undocumented.
* @param boolean $format Whether ACF should apply formatting to the field. Default false.
*
* @return mixed
*/
protected function get_acf_field_value( $root, $acf_field ) {
protected function get_acf_field_value( $root, $acf_field, $format = false ) {

$value = null;
$id = null;
Expand Down Expand Up @@ -416,7 +417,7 @@ protected function register_graphql_field( $type_name, $field_name, $config ) {
*
* @see: https://github.com/wp-graphql/wp-graphql-acf/issues/25
*/
if ( 0 === $acf_field['multiple'] ) {
if ( empty( $acf_field['multiple'] ) ) {
$field_config['type'] = 'String';
} else {
$field_config['type'] = [ 'list_of' => 'String' ];
Expand Down Expand Up @@ -445,18 +446,13 @@ protected function register_graphql_field( $type_name, $field_name, $config ) {
$field_config = [
'type' => 'String',
'resolve' => function( $root, $args, $context, $info ) use ( $acf_field ) {
if ( isset( $root->ID ) ) {
return get_field( $acf_field['key'], $root->ID, true );
}
//handle sub fields
if ( isset( $root[ $acf_field['key'] ] ) ) {
$value = $root[ $acf_field['key'] ];
$timestamp = strtotime( $value );

return date( $acf_field['return_format'], $timestamp );
}
$value = $this->get_acf_field_value( $root, $acf_field, true );

return null;
if ( ! empty( $value ) && ! empty( $acf_field['return_format'] ) ) {
$value = date( $acf_field['return_format'], $value );
}
return ! empty( $value ) ? $value : null;
},
];
break;
Expand Down Expand Up @@ -677,7 +673,7 @@ protected function register_graphql_field( $type_name, $field_name, $config ) {
];
break;
case 'user':

$type = 'User';

if ( isset( $acf_field['multiple'] ) && 1 === $acf_field['multiple'] ) {
Expand Down
8 changes: 5 additions & 3 deletions tests/wpunit/PostObjectFieldsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class PostObjectFieldsTest extends \Codeception\TestCase\WPTestCase {

public function setUp() {
parent::setUp(); // TODO: Change the autogenerated stub
WPGraphQL::__clear_schema();
WPGraphQL::clear_schema();
$this->group_key = __CLASS__;

$this->register_acf_field_group();
Expand Down Expand Up @@ -1150,7 +1150,7 @@ public function testQueryMultipleSelectFieldWithNoValueSet() {
$this->register_acf_field([
'name' => 'select_field_multiple',
'type' => 'select',
'show_in_graphql' => 1,
'show_in_graphql' => true,
'graphql_field_name' => 'selectMultiple',
'choices' => [
'one' => 'One',
Expand All @@ -1161,7 +1161,9 @@ public function testQueryMultipleSelectFieldWithNoValueSet() {
'multiple' => 1,
]);

delete_field( 'select_field_multiple', $this->post_id );
delete_post_meta( $this->post_id, 'select_field_multiple' );

codecept_debug( 'goo' );

$query = '
query GET_POST_WITH_ACF_FIELD( $postId: Int! ) {
Expand Down
2 changes: 1 addition & 1 deletion vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit2c922a3b1933e10e7ad3704a3cd98524::getLoader();
return ComposerAutoloaderInit0d1c0770bd52413713b6ce542771fda1::getLoader();
11 changes: 7 additions & 4 deletions vendor/composer/autoload_real.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// autoload_real.php @generated by Composer

class ComposerAutoloaderInit2c922a3b1933e10e7ad3704a3cd98524
class ComposerAutoloaderInit0d1c0770bd52413713b6ce542771fda1
{
private static $loader;

Expand All @@ -13,21 +13,24 @@ public static function loadClassLoader($class)
}
}

/**
* @return \Composer\Autoload\ClassLoader
*/
public static function getLoader()
{
if (null !== self::$loader) {
return self::$loader;
}

spl_autoload_register(array('ComposerAutoloaderInit2c922a3b1933e10e7ad3704a3cd98524', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit0d1c0770bd52413713b6ce542771fda1', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit2c922a3b1933e10e7ad3704a3cd98524', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit0d1c0770bd52413713b6ce542771fda1', 'loadClassLoader'));

$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require_once __DIR__ . '/autoload_static.php';

call_user_func(\Composer\Autoload\ComposerStaticInit2c922a3b1933e10e7ad3704a3cd98524::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit0d1c0770bd52413713b6ce542771fda1::getInitializer($loader));
} else {
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
Expand Down
8 changes: 4 additions & 4 deletions vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Composer\Autoload;

class ComposerStaticInit2c922a3b1933e10e7ad3704a3cd98524
class ComposerStaticInit0d1c0770bd52413713b6ce542771fda1
{
public static $prefixLengthsPsr4 = array (
'W' =>
Expand All @@ -29,9 +29,9 @@ class ComposerStaticInit2c922a3b1933e10e7ad3704a3cd98524
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit2c922a3b1933e10e7ad3704a3cd98524::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit2c922a3b1933e10e7ad3704a3cd98524::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit2c922a3b1933e10e7ad3704a3cd98524::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit0d1c0770bd52413713b6ce542771fda1::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit0d1c0770bd52413713b6ce542771fda1::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit0d1c0770bd52413713b6ce542771fda1::$classMap;

}, null, ClassLoader::class);
}
Expand Down

0 comments on commit 7d73316

Please sign in to comment.