Skip to content

Commit

Permalink
Merge pull request #3 from bleech/filter-parts
Browse files Browse the repository at this point in the history
Use hash to add params to a filter
  • Loading branch information
domtra authored Feb 10, 2017
2 parents 867cd7a + 9bfd644 commit 1eaf12a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/ACFComposer/ResolveConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ public static function forLayout($config, $parentKeys = []) {
protected static function forEntity($config, $requiredAttributes, $parentKeys = []) {
if (is_string($config)) {
$filterName = $config;
$config = apply_filters($filterName, null);
$filterParts = explode('#', $filterName);
if (isset($filterParts[1])) {
$config = apply_filters($filterParts[0], null, $filterParts[1]);
} else {
$config = apply_filters($filterName, null);
}


if (is_null($config)) {
trigger_error("ACFComposer: Filter {$filterName} does not exist!", E_USER_WARNING);
Expand Down
18 changes: 18 additions & 0 deletions tests/test-resolveConfigForField.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,24 @@ function testForFieldGetConfigFromFilter() {
'type' => 'someType'
];
Filters::expectApplied($config)
->with(null)
->once()
->andReturn($someField);
$output = ResolveConfig::forField($config);
$someField['key'] = "field_someField";
$this->assertEquals($someField, $output);
}

function testForFieldGetConfigFromFilterWithArguments() {
$config = 'ACFComposer/Fields/someField#argument';
$filter = 'ACFComposer/Fields/someField';
$someField = [
'name' => 'someField',
'label' => 'Some Field',
'type' => 'someType'
];
Filters::expectApplied($filter)
->with(null, 'argument')
->once()
->andReturn($someField);
$output = ResolveConfig::forField($config);
Expand Down

0 comments on commit 1eaf12a

Please sign in to comment.