From e463b0d891795efaca9a28258f7d59653e99ac59 Mon Sep 17 00:00:00 2001 From: ctippler Date: Thu, 18 Jul 2024 09:23:39 +0200 Subject: [PATCH 1/3] Bugfix: Prevent error/warning (#191) * Prevent error/warning "trim(): Argument #1 ($string) must be of type string, null given" because trim() is only applyable on strings - not if it is null * Apply php-cs-fixer changes --------- Co-authored-by: ctippler --- src/FilterService/FilterType/ElasticSearch/Input.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/FilterService/FilterType/ElasticSearch/Input.php b/src/FilterService/FilterType/ElasticSearch/Input.php index cbc81a5fa..bd3bf2059 100644 --- a/src/FilterService/FilterType/ElasticSearch/Input.php +++ b/src/FilterService/FilterType/ElasticSearch/Input.php @@ -42,7 +42,10 @@ public function addCondition(AbstractFilterDefinitionType $filterDefinition, Pro $value = $preSelect; } - $value = trim($value); + if(is_string($value)) { + $value = trim($value); + } + $currentFilter[$field] = $value; if (!empty($value)) { From 29eaf1b7d47d16a197ddf121378cf33e4c69fbc3 Mon Sep 17 00:00:00 2001 From: Paul Zerlauth Date: Tue, 27 Aug 2024 11:25:11 +0200 Subject: [PATCH 2/3] fix(filterDefinition): select preSelect values in backend ui (#194) --- .../indexfieldselectionfield/tags/indexFieldSelection.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Resources/public/js/indexfieldselectionfield/tags/indexFieldSelection.js b/src/Resources/public/js/indexfieldselectionfield/tags/indexFieldSelection.js index bf9645805..f6fdde6cd 100644 --- a/src/Resources/public/js/indexfieldselectionfield/tags/indexFieldSelection.js +++ b/src/Resources/public/js/indexfieldselectionfield/tags/indexFieldSelection.js @@ -62,10 +62,10 @@ pimcore.object.tags.indexFieldSelection = Class.create(pimcore.object.tags.selec load: function(store) { if(this.data) { if(this.preSelectCombobox.rendered) { - this.preSelectCombobox.setValue(this.data.preSelect); + this.preSelectCombobox.setValue(this.data.preSelect.split(',').map(Number)); } else { this.preSelectCombobox.addListener("afterRender", function() { - this.preSelectCombobox.setValue(this.data.preSelect); + this.preSelectCombobox.setValue(this.data.preSelect.split(',').map(Number)); }.bind(this)); } } @@ -239,10 +239,10 @@ pimcore.object.tags.indexFieldSelection = Class.create(pimcore.object.tags.selec if(this.fieldConfig.multiPreSelect == 'local_single' || this.fieldConfig.multiPreSelect == 'local_multi') { if(this.preSelectCombobox.rendered) { - this.preSelectCombobox.setValue(this.data.preSelect); + this.preSelectCombobox.setValue(this.data.preSelect.split(',').map(Number)); } else { this.preSelectCombobox.addListener("afterRender", function() { - this.preSelectCombobox.setValue(this.data.preSelect); + this.preSelectCombobox.setValue(this.data.preSelect.split(',').map(Number)); }.bind(this)); } } From 3a9f3dbf90d9d1e6613a5cbbf14053661fb12b3e Mon Sep 17 00:00:00 2001 From: Martin Hujer Date: Tue, 27 Aug 2024 11:25:21 +0200 Subject: [PATCH 3/3] IndexFieldSelection preSelect can also be integer (#192) When you use Index Service to index a relation, the ids are stored in database in INT column. When you try to use this indexed value in the filter and pre select a value, it cannot be saved because of the typehint. Steps to reproduce: 1. create a DataObject for FilterDefinition 2. add a "Filter Relation" to Filters 3. chose a value for "Pre Select" field 4. save the DataObject --- .../ObjectData/IndexFieldSelection.php | 12 ++++++------ src/FilterService/FilterType/AbstractFilterType.php | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/CoreExtensions/ObjectData/IndexFieldSelection.php b/src/CoreExtensions/ObjectData/IndexFieldSelection.php index 0aa8e7e7e..ba9157f98 100644 --- a/src/CoreExtensions/ObjectData/IndexFieldSelection.php +++ b/src/CoreExtensions/ObjectData/IndexFieldSelection.php @@ -23,14 +23,14 @@ class IndexFieldSelection public string $field; /** - * @var string|string[]|null + * @var string|string[]|int|null */ - public string|array|null $preSelect; + public string|array|int|null $preSelect; /** - * @param string|string[] $preSelect + * @param string|string[]|int $preSelect */ - public function __construct(?string $tenant, string $field, array|string|null $preSelect) + public function __construct(?string $tenant, string $field, array|string|int|null $preSelect) { $this->field = $field; $this->preSelect = $preSelect; @@ -50,7 +50,7 @@ public function getField(): string /** * @param string|string[] $preSelect */ - public function setPreSelect(array|string $preSelect): void + public function setPreSelect(array|string|int $preSelect): void { $this->preSelect = $preSelect; } @@ -58,7 +58,7 @@ public function setPreSelect(array|string $preSelect): void /** * @return string|string[]|null */ - public function getPreSelect(): array|string|null + public function getPreSelect(): array|string|int|null { return $this->preSelect; } diff --git a/src/FilterService/FilterType/AbstractFilterType.php b/src/FilterService/FilterType/AbstractFilterType.php index 153a7a5b2..5c69ec86c 100644 --- a/src/FilterService/FilterType/AbstractFilterType.php +++ b/src/FilterService/FilterType/AbstractFilterType.php @@ -81,7 +81,7 @@ protected function getTemplate(AbstractFilterDefinitionType $filterDefinition): return $template; } - protected function getPreSelect(AbstractFilterDefinitionType $filterDefinition): array|string|null + protected function getPreSelect(AbstractFilterDefinitionType $filterDefinition): array|string|int|null { $field = $filterDefinition->getField(); if ($field instanceof IndexFieldSelection) {