Skip to content

Commit dd246f6

Browse files
committed
Merge remote-tracking branch 'origin/MAUT-11515' into development
2 parents 81f12c7 + be332c6 commit dd246f6

9 files changed

+82
-8
lines changed

CustomFieldType/AbstractCustomFieldType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function getTableAlias(): string
6565
/**
6666
* @return mixed[]
6767
*/
68-
public function getOperators(): array
68+
public function getOperators(string $context = null): array
6969
{
7070
return $this->filterOperatorProvider->getAllOperators();
7171
}

CustomFieldType/AbstractMultivalueType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function getEntityClass(): string
5858
/**
5959
* @return mixed[]
6060
*/
61-
public function getOperators(): array
61+
public function getOperators(string $context = null): array
6262
{
6363
$allOperators = parent::getOperators();
6464
$allowedOperators = array_flip(['empty', '!empty', 'in', '!in']);

CustomFieldType/AbstractTextType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function getEntityClass(): string
3434
/**
3535
* @return mixed[]
3636
*/
37-
public function getOperators(): array
37+
public function getOperators(string $context = null): array
3838
{
3939
$allOperators = parent::getOperators();
4040
$allowedOperators = array_flip(['=', '!=', 'empty', '!empty', 'like', '!like', 'startsWith', 'endsWith', 'contains']);

CustomFieldType/CustomFieldTypeInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function getTableAlias(): string;
6060
/**
6161
* @return mixed[]
6262
*/
63-
public function getOperators(): array;
63+
public function getOperators(string $context = null): array;
6464

6565
/**
6666
* @return mixed[]

CustomFieldType/DateOperatorTrait.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ public function getOperatorOptions(): array
2323
/**
2424
* @return mixed[]
2525
*/
26-
public function getOperators(): array
26+
public function getOperators(string $context = null): array
2727
{
2828
$allOperators = parent::getOperators();
29+
if ('segment' === $context) {
30+
return $allOperators;
31+
}
2932
$allowedOperators = array_flip(['=', '!=', 'gt', 'gte', 'lt', 'lte', 'empty', '!empty', 'between', '!between', 'inLast', 'inNext']);
3033

3134
return array_intersect_key($allOperators, $allowedOperators);

CustomFieldType/IntType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function getOperatorOptions(): array
5858
/**
5959
* @return mixed[]
6060
*/
61-
public function getOperators(): array
61+
public function getOperators(string $context = null): array
6262
{
6363
$allOperators = parent::getOperators();
6464
$allowedOperators = array_flip(['=', '!=', 'gt', 'gte', 'lt', 'lte', 'empty', '!empty', 'between', '!between']);

CustomFieldType/SelectType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function getSymfonyFormFieldType(): string
3636
/**
3737
* @return mixed[]
3838
*/
39-
public function getOperators(): array
39+
public function getOperators(string $context = null): array
4040
{
4141
$allOperators = parent::getOperators();
4242
$allowedOperators = array_flip(['=', '!=', 'empty', '!empty']);

EventListener/SegmentFiltersChoicesGenerateSubscriber.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ function (CustomObject $customObject) use ($event, $fieldTypes): void {
9595
continue;
9696
}
9797

98-
$allowedOperators = $customField->getTypeObject()->getOperators();
98+
$context = method_exists($this->typeOperatorProvider, 'getContext') ? $this->typeOperatorProvider->getContext() : '';
99+
$allowedOperators = $customField->getTypeObject()->getOperators($context);
99100
$typeOperators = $this->typeOperatorProvider->getOperatorsForFieldType($customField->getType());
100101
$availableOperators = array_flip($typeOperators);
101102
$operators = array_intersect_key($availableOperators, $allowedOperators);

Tests/Functional/Helper/QueryFilterHelperTest.php

+70
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,76 @@ public function testGetCustomValueValueExpression(): void
147147
]
148148
);
149149

150+
$this->assertMatchWhere(
151+
'test_value.value LIKE :par5',
152+
[
153+
'glue' => 'and',
154+
'field' => 'cmf_'.$this->getFixtureById('custom_field1')->getId(),
155+
'object' => 'custom_object',
156+
'type' => 'datetime',
157+
'operator' => 'like',
158+
'properties' => [
159+
'filter' => '2024',
160+
],
161+
]
162+
);
163+
164+
$this->assertMatchWhere(
165+
'test_value.value REGEXP :par6',
166+
[
167+
'glue' => 'and',
168+
'field' => 'cmf_'.$this->getFixtureById('custom_field1')->getId(),
169+
'object' => 'custom_object',
170+
'type' => 'datetime',
171+
'operator' => 'regexp',
172+
'properties' => [
173+
'filter' => '2024',
174+
],
175+
]
176+
);
177+
178+
$this->assertMatchWhere(
179+
'test_value.value LIKE :par7',
180+
[
181+
'glue' => 'and',
182+
'field' => 'cmf_'.$this->getFixtureById('custom_field1')->getId(),
183+
'object' => 'custom_object',
184+
'type' => 'datetime',
185+
'operator' => 'startsWith',
186+
'properties' => [
187+
'filter' => '2024',
188+
],
189+
]
190+
);
191+
192+
$this->assertMatchWhere(
193+
'test_value.value LIKE :par8',
194+
[
195+
'glue' => 'and',
196+
'field' => 'cmf_'.$this->getFixtureById('custom_field1')->getId(),
197+
'object' => 'custom_object',
198+
'type' => 'datetime',
199+
'operator' => 'endsWith',
200+
'properties' => [
201+
'filter' => '2024',
202+
],
203+
]
204+
);
205+
206+
$this->assertMatchWhere(
207+
'test_value.value LIKE :par9',
208+
[
209+
'glue' => 'and',
210+
'field' => 'cmf_'.$this->getFixtureById('custom_field1')->getId(),
211+
'object' => 'custom_object',
212+
'type' => 'datetime',
213+
'operator' => 'contains',
214+
'properties' => [
215+
'filter' => '2024',
216+
],
217+
]
218+
);
219+
150220
$this->assertMatchWhere(
151221
'test_value.value IS NULL',
152222
[

0 commit comments

Comments
 (0)