Skip to content

Commit

Permalink
Merge branch 'MAUT-11602' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
escopecz committed Jun 25, 2024
2 parents 736d890 + 850a962 commit 8a1fae0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 22 deletions.
33 changes: 33 additions & 0 deletions CustomFieldType/DateOperatorTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace MauticPlugin\CustomObjectsBundle\CustomFieldType;

trait DateOperatorTrait
{
/**
* Remove operators that are supported only by segment filters.
*
* @return string[]
*/
public function getOperatorOptions(): array
{
$options = parent::getOperatorOptions();

unset($options['between'], $options['!between'], $options['inLast'], $options['inNext']);

return $options;
}

/**
* @return mixed[]
*/
public function getOperators(): array
{
$allOperators = parent::getOperators();
$allowedOperators = array_flip(['=', '!=', 'gt', 'gte', 'lt', 'lte', 'empty', '!empty', 'between', '!between', 'inLast', 'inNext']);

return array_intersect_key($allOperators, $allowedOperators);
}
}
13 changes: 2 additions & 11 deletions CustomFieldType/DateTimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

class DateTimeType extends AbstractCustomFieldType
{
use DateOperatorTrait;

/**
* @var string
*/
Expand Down Expand Up @@ -70,17 +72,6 @@ public function getEntityClass(): string
return CustomFieldValueDateTime::class;
}

/**
* @return mixed[]
*/
public function getOperators(): array
{
$allOperators = parent::getOperators();
$allowedOperators = array_flip(['=', '!=', 'gt', 'gte', 'lt', 'lte', 'empty', '!empty', 'between', '!between', 'inLast', 'inNext']);

return array_intersect_key($allOperators, $allowedOperators);
}

/**
* {@inheritdoc}
*/
Expand Down
13 changes: 2 additions & 11 deletions CustomFieldType/DateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

class DateType extends AbstractCustomFieldType
{
use DateOperatorTrait;

/**
* @var string
*/
Expand Down Expand Up @@ -70,17 +72,6 @@ public function getEntityClass(): string
return CustomFieldValueDate::class;
}

/**
* @return mixed[]
*/
public function getOperators(): array
{
$allOperators = parent::getOperators();
$allowedOperators = array_flip(['=', '!=', 'gt', 'gte', 'lt', 'lte', 'empty', '!empty', 'between', '!between', 'inLast', 'inNext']);

return array_intersect_key($allOperators, $allowedOperators);
}

/**
* {@inheritdoc}
*/
Expand Down
14 changes: 14 additions & 0 deletions CustomFieldType/IntType.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ public function createValueEntity(CustomField $customField, CustomItem $customIt
return new CustomFieldValueInt($customField, $customItem, (int) $value);
}

/**
* Remove operators that are supported only by segment filters.
*
* @return string[]
*/
public function getOperatorOptions(): array
{
$options = parent::getOperatorOptions();

unset($options['between'], $options['!between']);

return $options;
}

/**
* @return mixed[]
*/
Expand Down

0 comments on commit 8a1fae0

Please sign in to comment.