Skip to content

Commit 31d3436

Browse files
authored
Merge pull request #12 from statikbe/queryfilter
[Feature] Allow creating entry selection queries using config values
2 parents 951849b + ac7c0a8 commit 31d3436

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

src/fields/ConfigValuesFieldField.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use statikbe\configvaluesfield\assetbundles\configvalues\ConfigValuesAsset;
2121
use statikbe\configvaluesfield\ConfigValuesField;
2222

23+
2324
/**
2425
* @author Statik.be
2526
* @package ConfigValuesField
@@ -216,4 +217,9 @@ private function getOptions(): array
216217

217218
return $data;
218219
}
220+
221+
public function getElementConditionRuleType(): array|string|null
222+
{
223+
return ConfigValuesFieldConditionRule::class;
224+
}
219225
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace statikbe\configvaluesfield\fields\conditions;
4+
5+
use statikbe\configvaluesfield\ConfigValuesField;
6+
use craft\base\conditions\BaseMultiSelectConditionRule;
7+
use craft\fields\conditions\FieldConditionRuleInterface;
8+
use craft\fields\conditions\FieldConditionRuleTrait;
9+
use statikbe\configvaluesfield\fields\ConfigValuesFieldField;
10+
use yii\base\InvalidConfigException;
11+
12+
class ConfigValuesFieldConditionRule extends BaseMultiSelectConditionRule implements FieldConditionRuleInterface
13+
{
14+
use FieldConditionRuleTrait;
15+
16+
/**
17+
* @inheritdoc
18+
*/
19+
protected function options(): array
20+
{
21+
if (!$this->field() instanceof ConfigValuesFieldField) {
22+
return [];
23+
}
24+
25+
return ConfigValuesField::getInstance()->getSettings()->data[$this->field()->dataSet];
26+
}
27+
28+
/**
29+
* @inheritdoc
30+
*/
31+
protected function inputHtml(): string
32+
{
33+
if (!$this->field() instanceof ConfigValuesFieldField) {
34+
throw new InvalidConfigException();
35+
}
36+
37+
return parent::inputHtml();
38+
}
39+
40+
/**
41+
* @inheritdoc
42+
*/
43+
protected function elementQueryParam(): ?array
44+
{
45+
if (!$this->field() instanceof ConfigValuesFieldField) {
46+
return null;
47+
}
48+
49+
return $this->paramValue();
50+
}
51+
52+
/**
53+
* @inheritdoc
54+
*/
55+
protected function matchFieldValue($value): bool
56+
{
57+
if (!$this->field() instanceof ConfigValuesFieldField) {
58+
return true;
59+
}
60+
61+
return $this->matchValue($value);
62+
}
63+
}

0 commit comments

Comments
 (0)