mirror of
https://github.com/SuiteCRM/SuiteCRM-Core.git
synced 2025-09-02 08:09:19 +08:00
[Legacy] Fix Empty Dropdown Values
This commit is contained in:
parent
d3f3882856
commit
d3a68fb18c
6 changed files with 78 additions and 3 deletions
|
@ -104,6 +104,7 @@ class FilterMapper
|
|||
if ($isRegularValue) {
|
||||
$fieldKey = str_replace('_advanced', '', $key);
|
||||
$filter['field'] = $fieldKey;
|
||||
$filter['fieldType'] = $contents["field_type_{$fieldKey}"] ?? '';
|
||||
|
||||
$values = [];
|
||||
if (is_string($value)) {
|
||||
|
@ -112,10 +113,10 @@ class FilterMapper
|
|||
|
||||
if (is_array($value)) {
|
||||
$values = $value;
|
||||
$values = $this->mapToApi($filter, $values);
|
||||
}
|
||||
|
||||
$filter['values'] = $values;
|
||||
$filter['fieldType'] = $contents["field_type_${fieldKey}"] ?? '';
|
||||
$filters[$fieldKey] = $filter;
|
||||
continue;
|
||||
}
|
||||
|
@ -228,4 +229,44 @@ class FilterMapper
|
|||
{
|
||||
return $sort['sortOrder'] ?? 'DESC';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $fieldType
|
||||
* @return FilterMapperInterface|null
|
||||
*/
|
||||
public function getMapper($fieldType): ?FilterMapperInterface
|
||||
{
|
||||
if ($this->mappers->hasMapper($fieldType)) {
|
||||
$mapper = $this->mappers->get($fieldType);
|
||||
} else {
|
||||
$mapper = $this->mappers->get('default');
|
||||
}
|
||||
return $mapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $filter
|
||||
* @param array $values
|
||||
* @return array
|
||||
*/
|
||||
public function mapToApi(array $filter, array $values): array
|
||||
{
|
||||
$mapper = $this->getMapper($filter['fieldType'] ?? '');
|
||||
|
||||
if ($mapper === null) {
|
||||
return $values;
|
||||
}
|
||||
|
||||
$mappedValues = [];
|
||||
foreach ($values as $key => $item) {
|
||||
if (!is_string($item)) {
|
||||
$mappedValues[$key] = $item;
|
||||
continue;
|
||||
}
|
||||
|
||||
$mappedValues[$key] = $mapper->toApi($item, $filter);
|
||||
}
|
||||
|
||||
return $mappedValues;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,4 +40,12 @@ interface FilterMapperInterface
|
|||
* @return mixed|string|string[]
|
||||
*/
|
||||
public function mapValue(string $mappedValue, array $criteriaItem);
|
||||
|
||||
/**
|
||||
* To Api
|
||||
* @param string $mappedValue
|
||||
* @param array $criteriaItem
|
||||
* @return mixed|string|string[]
|
||||
*/
|
||||
public function toApi(string $mappedValue, array $criteriaItem);
|
||||
}
|
||||
|
|
|
@ -79,4 +79,9 @@ class DateFilterMapper implements FilterMapperInterface
|
|||
|
||||
return $legacyValue;
|
||||
}
|
||||
|
||||
public function toApi(string $mappedValue, array $criteriaItem): string
|
||||
{
|
||||
return $mappedValue;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,4 +79,9 @@ class DateTimeFilterMapper implements FilterMapperInterface
|
|||
|
||||
return $legacyValue;
|
||||
}
|
||||
|
||||
public function toApi(string $mappedValue, array $criteriaItem): string
|
||||
{
|
||||
return $mappedValue;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,10 +49,12 @@ class DefaultFilterMapper implements FilterMapperInterface
|
|||
return [];
|
||||
}
|
||||
|
||||
|
||||
$legacyValue = $values;
|
||||
|
||||
$mapEmptyString = false;
|
||||
foreach ($legacyValue as $legacyValueKey => $legacyValueValue){
|
||||
foreach ($legacyValue as $legacyValueKey => $legacyValueValue) {
|
||||
|
||||
switch ($legacyValueValue) {
|
||||
case "__SuiteCRMEmptyString__":
|
||||
$mapEmptyString = true;
|
||||
|
@ -61,7 +63,7 @@ class DefaultFilterMapper implements FilterMapperInterface
|
|||
}
|
||||
}
|
||||
|
||||
if ($mapEmptyString){
|
||||
if ($mapEmptyString) {
|
||||
return $legacyValue;
|
||||
}
|
||||
|
||||
|
@ -71,4 +73,13 @@ class DefaultFilterMapper implements FilterMapperInterface
|
|||
|
||||
return $legacyValue;
|
||||
}
|
||||
|
||||
public function toApi(string $mappedValue, array $criteriaItem): string
|
||||
{
|
||||
if ($criteriaItem['fieldType'] === 'enum' && $mappedValue === '') {
|
||||
$mappedValue = "__SuiteCRMEmptyString__";
|
||||
}
|
||||
|
||||
return $mappedValue;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,4 +51,9 @@ class MultiEnumFilterMapper implements FilterMapperInterface
|
|||
|
||||
return $criteriaItem['values'];
|
||||
}
|
||||
|
||||
public function toApi(string $mappedValue, array $criteriaItem): string
|
||||
{
|
||||
return $mappedValue;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue