Skip to content

Commit

Permalink
feat(ResolveConfig): basic resolve for field groups
Browse files Browse the repository at this point in the history
  • Loading branch information
domtra committed Nov 8, 2016
1 parent cc670a6 commit d2438df
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/ACFComposer/ResolveConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@
use Exception;

class ResolveConfig {
public static function forFieldGroup($config) {
$output = self::validateConfig($config, ['name', 'title', 'fields', 'location']);

$keySuffix = $output['name'];
$output['key'] = "group_{$keySuffix}";
$output = self::forNestedEntities($output, $keySuffix);
$output['fields'] = array_map(function($field) use ($keySuffix){
return self::forField($field, $keySuffix);
}, $output['fields']);
return $output;
}

public static function forField($config, $keySuffix = '') {
return self::forEntity($config, ['name', 'label', 'type'], $keySuffix);
}
Expand Down
35 changes: 35 additions & 0 deletions tests/test-resolveConfigForFieldGroup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

require_once dirname(__DIR__) . '/lib/ACFComposer/ResolveConfig.php';

use ACFComposer\TestCase;
use ACFComposer\ResolveConfig;
use Brain\Monkey\WP\Filters;

class ResolveConfigForFieldGroupTest extends TestCase {
function testForFieldGroupWithValidConfig() {
$fieldConfig = [
'name' => 'someField',
'label' => 'Some Field',
'type' => 'someType'
];
$locationConfig = [
'param' => 'someParam',
'operator' => 'someOperator',
'value' => 'someValue'
];
$config = [
'name' => 'someGroup',
'title' => 'Some Group',
'fields' => [$fieldConfig],
'location' => [
[$locationConfig]
]
];
$output = ResolveConfig::forFieldGroup($config);
$fieldConfig['key'] = 'field_someGroup_someField';
$config['key'] = 'group_someGroup';
$config['fields'] = [$fieldConfig];
$this->assertEquals($config, $output);
}
}

0 comments on commit d2438df

Please sign in to comment.