Skip to content

Commit 1eaf12a

Browse files
authored
Merge pull request #3 from bleech/filter-parts
Use hash to add params to a filter
2 parents 867cd7a + 9bfd644 commit 1eaf12a

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/ACFComposer/ResolveConfig.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ public static function forLayout($config, $parentKeys = []) {
4040
protected static function forEntity($config, $requiredAttributes, $parentKeys = []) {
4141
if (is_string($config)) {
4242
$filterName = $config;
43-
$config = apply_filters($filterName, null);
43+
$filterParts = explode('#', $filterName);
44+
if (isset($filterParts[1])) {
45+
$config = apply_filters($filterParts[0], null, $filterParts[1]);
46+
} else {
47+
$config = apply_filters($filterName, null);
48+
}
49+
4450

4551
if (is_null($config)) {
4652
trigger_error("ACFComposer: Filter {$filterName} does not exist!", E_USER_WARNING);

tests/test-resolveConfigForField.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,24 @@ function testForFieldGetConfigFromFilter() {
6464
'type' => 'someType'
6565
];
6666
Filters::expectApplied($config)
67+
->with(null)
68+
->once()
69+
->andReturn($someField);
70+
$output = ResolveConfig::forField($config);
71+
$someField['key'] = "field_someField";
72+
$this->assertEquals($someField, $output);
73+
}
74+
75+
function testForFieldGetConfigFromFilterWithArguments() {
76+
$config = 'ACFComposer/Fields/someField#argument';
77+
$filter = 'ACFComposer/Fields/someField';
78+
$someField = [
79+
'name' => 'someField',
80+
'label' => 'Some Field',
81+
'type' => 'someType'
82+
];
83+
Filters::expectApplied($filter)
84+
->with(null, 'argument')
6785
->once()
6886
->andReturn($someField);
6987
$output = ResolveConfig::forField($config);

0 commit comments

Comments
 (0)