From c1d69bbc74204b551ec15cc8aeb1112f0bf80f68 Mon Sep 17 00:00:00 2001 From: Filip Szenborn Date: Fri, 25 Jun 2021 15:17:23 +0200 Subject: [PATCH 01/16] Filter by relation on Grid 1.0 --- .../element/helpers/gridColumnConfig.js | 107 ++++++++++++++++++ .../pimcore/object/helpers/gridTabAbstract.js | 4 + .../tags/advancedManyToManyObjectRelation.js | 1 + .../object/tags/advancedManyToManyRelation.js | 15 ++- .../js/pimcore/object/tags/hotspotimage.js | 4 + .../public/js/pimcore/object/tags/image.js | 4 + .../object/tags/manyToManyObjectRelation.js | 12 ++ .../pimcore/object/tags/manyToManyRelation.js | 12 ++ .../pimcore/object/tags/manyToOneRelation.js | 4 + .../RelationFilterConditionParser.php | 48 ++++++++ .../ClassDefinition/Data/Hotspotimage.php | 16 +++ .../DataObject/ClassDefinition/Data/Image.php | 14 +++ .../Data/ManyToManyObjectRelation.php | 15 ++- .../Data/ManyToManyRelation.php | 15 ++- .../Data/ManyToOneRelation.php | 14 +++ 15 files changed, 282 insertions(+), 3 deletions(-) create mode 100644 models/DataObject/ClassDefinition/Data/Extension/RelationFilterConditionParser.php diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/element/helpers/gridColumnConfig.js b/bundles/AdminBundle/Resources/public/js/pimcore/element/helpers/gridColumnConfig.js index 6b4d125ac6a..8496f90674d 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/element/helpers/gridColumnConfig.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/element/helpers/gridColumnConfig.js @@ -263,6 +263,7 @@ pimcore.element.helpers.gridColumnConfig = { var menu = grid.headerCt.getMenu(); menu.add(columnConfig); // + var batchAllMenu = new Ext.menu.Item({ text: t("batch_change"), iconCls: "pimcore_icon_table pimcore_icon_overlay_go", @@ -330,11 +331,28 @@ pimcore.element.helpers.gridColumnConfig = { }); menu.add(batchRemoveSelectedMenu); + var filterByRelationMenu = new Ext.menu.Item({ + text: t("Filter by relation"), + iconCls: "pimcore_icon_filter pimcore_icon_overlay_add", + handler: function (grid) { + var menu = grid.headerCt.getMenu(); + var column = menu.activeHeader; + this.filterPrepare(column); + }.bind(this, grid) + }); + menu.add(filterByRelationMenu); + // menu.on('beforeshow', function (batchAllMenu, batchSelectedMenu, grid) { var menu = grid.headerCt.getMenu(); var columnDataIndex = menu.activeHeader.dataIndex; + if (menu.activeHeader.config && typeof menu.activeHeader.config.getRelationFilter === "function") { + filterByRelationMenu.hide(); + } else { + filterByRelationMenu.show(); + } + // no batch for system properties if (Ext.Array.contains(this.systemColumns, columnDataIndex) || Ext.Array.contains(this.noBatchColumns, columnDataIndex)) { batchAllMenu.hide(); @@ -362,6 +380,95 @@ pimcore.element.helpers.gridColumnConfig = { }.bind(this, batchAllMenu, batchSelectedMenu, grid)); }, + filterPrepare: function (column) { + var dataIndexName = column.dataIndex + var gridColumns = this.grid.getColumns(); + var columnIndex = -1; + for (let i = 0; i < gridColumns.length; i++) { + let dataIndex = gridColumns[i].dataIndex; + if (dataIndex == dataIndexName) { + columnIndex = i; + break; + } + } + if (columnIndex < 0) { + return; + } + + if (this.systemColumns.indexOf(gridColumns[columnIndex].dataIndex) > -1) { + return; + } + + var fieldInfo = this.grid.getColumns()[columnIndex].config; + + if((this.objecttype === "object") || (this.objecttype === "variant")) { + if (!fieldInfo.layout || !fieldInfo.layout.layout) { + return; + } + + if (fieldInfo.layout.layout.noteditable) { + Ext.MessageBox.alert(t('error'), t('this_element_cannot_be_edited')); + return; + } + + var tagType = fieldInfo.layout.type; + var editor = new pimcore.object.tags[tagType](null, fieldInfo.layout.layout); + editor.setObject(this.object); + } + + editor.updateContext({ + containerType: "filterByRelationWindow" + }); + + var formPanel = Ext.create('Ext.form.Panel', { + xtype: "form", + border: false, + items: [editor.getLayoutEdit()], + bodyStyle: "padding: 10px;", + buttons: [ + { + text: t("Clear active relation filter"), + iconCls: "pimcore_icon_filter_condition pimcore_icon_overlay_delete", + handler: function () { + this.filterByRelationWindow.close(); + this.grid.store.filters.removeByKey("x-gridfilter-"+fieldInfo.dataIndex); + }.bind(this) + }, + { + text: t("Apply filter"), + iconCls: "pimcore_icon_filter pimcore_icon_overlay_add", + handler: function () { + if (formPanel.isValid() && typeof fieldInfo.getRelationFilterCondition === "function") { + this.grid.filters.getStore().addFilter( + new Ext.util.Filter({ + operator: "like", + type: "string", + id: "x-gridfilter-" + fieldInfo.dataIndex, + property: fieldInfo.dataIndex, + value: fieldInfo.getRelationFilterCondition(editor) + }) + ); + this.filterByRelationWindow.close(); + } + }.bind(this) + } + ] + }); + + var title = "Filter by relation field " + fieldInfo.text; + this.filterByRelationWindow = new Ext.Window({ + autoScroll: true, + modal: false, + title: title, + items: [formPanel], + bodyStyle: "background: #fff;", + width: 700, + maxHeight: 650 + }); + this.filterByRelationWindow.show(); + this.filterByRelationWindow.updateLayout(); + }, + batchPrepare: function (column, onlySelected, append, remove) { var dataIndexName = column.dataIndex var gridColumns = this.grid.getColumns(); diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/helpers/gridTabAbstract.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/helpers/gridTabAbstract.js index 7ece2a15d1f..7ca3a6c79f4 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/helpers/gridTabAbstract.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/helpers/gridTabAbstract.js @@ -207,6 +207,7 @@ pimcore.object.helpers.gridTabAbstract = Class.create({ } ); + this.grid.getStore().clearFilter() this.grid.filters.clearFilters(); this.pagingtoolbar.moveFirst(); @@ -232,6 +233,7 @@ pimcore.object.helpers.gridTabAbstract = Class.create({ ); proxy.setExtraParam("condition", this.sqlEditor.getValue()); if (this.grid && this.grid.filters) { + this.grid.getStore().clearFilter() this.grid.filters.clearFilters(); } @@ -295,6 +297,7 @@ pimcore.object.helpers.gridTabAbstract = Class.create({ text: t("clear_filters"), tooltip: t("clear_filters"), handler: function (button) { + this.grid.getStore().clearFilter() this.grid.filters.clearFilters(); this.toolbarFilterInfo.hide(); this.clearFilterButton.hide(); @@ -313,6 +316,7 @@ pimcore.object.helpers.gridTabAbstract = Class.create({ "change": function (field, checked) { this.grid.getStore().setRemoteFilter(false); this.grid.filters.clearFilters(); + this.grid.getStore().clearFilter() this.store.getProxy().setExtraParam("only_direct_children", checked); diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/advancedManyToManyObjectRelation.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/advancedManyToManyObjectRelation.js index 700ecd52f83..d44a3609de9 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/advancedManyToManyObjectRelation.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/advancedManyToManyObjectRelation.js @@ -599,6 +599,7 @@ pimcore.object.tags.advancedManyToManyObjectRelation = Class.create(pimcore.obje return { text: t(field.label), width: 150, sortable: false, dataIndex: field.key, getEditor: this.getWindowCellEditor.bind(this, field), + getRelationFilterCondition: this.getRelationFilterCondition, renderer: pimcore.object.helpers.grid.prototype.advancedRelationGridRenderer.bind(this, field, "fullpath") }; }, diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/advancedManyToManyRelation.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/advancedManyToManyRelation.js index ba208bb510f..8c5d3293f91 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/advancedManyToManyRelation.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/advancedManyToManyRelation.js @@ -941,10 +941,23 @@ pimcore.object.tags.advancedManyToManyRelation = Class.create(pimcore.object.tag return { text: t(field.label), width: 150, sortable: false, dataIndex: field.key, getEditor: this.getWindowCellEditor.bind(this, field), - renderer: pimcore.object.helpers.grid.prototype.advancedRelationGridRenderer.bind(this, field, "path") + getRelationFilterCondition: this.getRelationFilterCondition, + renderer: pimcore.object.helpers.grid.prototype.advancedRelationGridRenderer.bind(this, field, "path"), }; }, + getRelationFilterCondition: function (editor) { + var filterResult = []; + editor.store.getData().items.forEach( + function (item) { + filterResult.push(item.data.type + "|" + item.data.id); + } + ); + filterResult = filterResult.join(','); + + return filterResult; + }, + getCellEditValue: function () { return this.getValue(); } diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/hotspotimage.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/hotspotimage.js index 17427d45c72..86cb12a481b 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/hotspotimage.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/hotspotimage.js @@ -54,6 +54,10 @@ pimcore.object.tags.hotspotimage = Class.create(pimcore.object.tags.image, { return { text: t(field.label), width: 100, sortable: false, dataIndex: field.key, getEditor: this.getWindowCellEditor.bind(this, field), + getRelationFilterCondition: function(editor) { + var filterResult = editor.data ? editor.data.id : null; + return filterResult; + }, renderer: function (key, value, metaData, record, rowIndex, colIndex, store, view) { this.applyPermissionStyle(key, value, metaData, record); diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/image.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/image.js index e40f52d93e5..2a7fe28d192 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/image.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/image.js @@ -32,6 +32,10 @@ pimcore.object.tags.image = Class.create(pimcore.object.tags.abstract, { return { text: t(field.label), width: 100, sortable: false, dataIndex: field.key, getEditor: this.getWindowCellEditor.bind(this, field), + getRelationFilterCondition: function(editor) { + var filterResult = editor.data ? editor.data.id : null; + return filterResult; + }, renderer: function (key, value, metaData, record, rowIndex, colIndex, store, view) { this.applyPermissionStyle(key, value, metaData, record); diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyObjectRelation.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyObjectRelation.js index 0c34d50d2bb..6e5f5b11064 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyObjectRelation.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyObjectRelation.js @@ -88,10 +88,22 @@ pimcore.object.tags.manyToManyObjectRelation = Class.create(pimcore.object.tags. return result.join("
"); } }.bind(this, field.key), + getRelationFilterCondition: this.getRelationFilterCondition, getEditor: this.getWindowCellEditor.bind(this, field) }; }, + getRelationFilterCondition: function (editor) { + var filterResult = []; + editor.store.getData().items.forEach( + function (item) { + filterResult.push(item.data.id); + }); + filterResult = filterResult.join(','); + + return filterResult; + }, + openParentSearchEditor: function () { pimcore.helpers.itemselector(false, function (selection) { this.parentField.setValue(selection.fullpath); diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyRelation.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyRelation.js index b95c95ec00a..6a5ea1356fe 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyRelation.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyRelation.js @@ -76,6 +76,7 @@ pimcore.object.tags.manyToManyRelation = Class.create(pimcore.object.tags.abstra return { text: t(field.label), width: 150, sortable: false, dataIndex: field.key, getEditor: this.getWindowCellEditor.bind(this, field), + getRelationFilterCondition: this.getRelationFilterCondition, renderer: function (key, value, metaData, record) { this.applyPermissionStyle(key, value, metaData, record); @@ -100,6 +101,17 @@ pimcore.object.tags.manyToManyRelation = Class.create(pimcore.object.tags.abstra }; }, + getRelationFilterCondition: function (editor) { + var filterResult = []; + editor.store.getData().items.forEach( + function (item) { + filterResult.push(item.data.type + "|" + item.data.id); + }); + filterResult = filterResult.join(','); + + return filterResult; + }, + getLayoutEdit: function () { var autoHeight = false; if (!this.fieldConfig.height) { diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToOneRelation.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToOneRelation.js index fff6dac7d42..bf987935641 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToOneRelation.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToOneRelation.js @@ -55,6 +55,10 @@ pimcore.object.tags.manyToOneRelation = Class.create(pimcore.object.tags.abstrac return { text: t(field.label), sortable: false, dataIndex: field.key, renderer: renderer, + getRelationFilterCondition: function(editor) { + var filterResult = editor.data ? editor.data.id : null; + return filterResult; + }, getEditor: this.getWindowCellEditor.bind(this, field) }; }, diff --git a/models/DataObject/ClassDefinition/Data/Extension/RelationFilterConditionParser.php b/models/DataObject/ClassDefinition/Data/Extension/RelationFilterConditionParser.php new file mode 100644 index 00000000000..30858589412 --- /dev/null +++ b/models/DataObject/ClassDefinition/Data/Extension/RelationFilterConditionParser.php @@ -0,0 +1,48 @@ + + */ +declare(strict_types=1); + +namespace Pimcore\Model\DataObject\ClassDefinition\Data\Extension; + +/** + * Trait RelationFilterConditionParser + * @package Pimcore\Model\DataObject\ClassDefinition\Data\Extension + */ +trait RelationFilterConditionParser +{ + /** + * Parses filter value of a relation field and creates the filter condition + * @param $value + * @param $operator + * @param $name + * @return string + */ + public function getRelationFilterCondition($value, $operator, $name) + { + if ($operator == '=') { + $value = "'%," . $value . ",%'"; + return '`' . $name . '` LIKE ' . $value . ' '; + } elseif ($operator == 'LIKE') { + $result = $name . " IS NULL"; + $values = explode(',', $value ?? ''); + if (is_array($values) && !empty($values)) { + $fieldConditions = []; + foreach ($values as $value) { + if (empty($value)) { + continue; + } + $fieldConditions[] = '`' . $name . "` LIKE '%" . $value . "%' "; + } + if (!empty($fieldConditions)) { + $result = '(' . implode(' AND ', $fieldConditions) . ')'; + } + } + return $result; + } + return "1=1"; + } +} diff --git a/models/DataObject/ClassDefinition/Data/Hotspotimage.php b/models/DataObject/ClassDefinition/Data/Hotspotimage.php index 580eb64b074..6c3f77330d1 100644 --- a/models/DataObject/ClassDefinition/Data/Hotspotimage.php +++ b/models/DataObject/ClassDefinition/Data/Hotspotimage.php @@ -29,6 +29,7 @@ class Hotspotimage extends Data implements ResourcePersistenceAwareInterface, Qu use ImageTrait; use DataObject\Traits\SimpleComparisonTrait; use Extension\QueryColumnType; + use DataObject\ClassDefinition\Data\Extension\RelationFilterConditionParser; /** * Static type of this element @@ -685,4 +686,19 @@ public function denormalize($value, $params = []) return $image; } } + + /** + * Filter by relation feature + * @param array|string $value + * @param string $operator + * @param array $params + * @return string + */ + public function getFilterConditionExt($value, $operator, $params = []) + { + $name = $params['name'] ?: $this->name; + $name .= '__image'; + return $this->getRelationFilterCondition($value, $operator, $name); + } + } diff --git a/models/DataObject/ClassDefinition/Data/Image.php b/models/DataObject/ClassDefinition/Data/Image.php index 955a82a0800..71fd332c868 100644 --- a/models/DataObject/ClassDefinition/Data/Image.php +++ b/models/DataObject/ClassDefinition/Data/Image.php @@ -26,6 +26,7 @@ class Image extends Data implements ResourcePersistenceAwareInterface, QueryReso use Extension\ColumnType; use ImageTrait; use Extension\QueryColumnType; + use Data\Extension\RelationFilterConditionParser; /** * Static type of this element @@ -374,4 +375,17 @@ public function denormalize($value, $params = []) return Asset\Image::getById($value['id']); } } + + /** + * Filter by relation feature + * @param array|string $value + * @param string $operator + * @param array $params + * @return string + */ + public function getFilterConditionExt($value, $operator, $params = []) + { + $name = $params['name'] ?: $this->name; + return $this->getRelationFilterCondition($value, $operator, $name); + } } diff --git a/models/DataObject/ClassDefinition/Data/ManyToManyObjectRelation.php b/models/DataObject/ClassDefinition/Data/ManyToManyObjectRelation.php index 0e001dd0c9d..a7799b9b801 100644 --- a/models/DataObject/ClassDefinition/Data/ManyToManyObjectRelation.php +++ b/models/DataObject/ClassDefinition/Data/ManyToManyObjectRelation.php @@ -28,7 +28,7 @@ class ManyToManyObjectRelation extends AbstractRelations implements QueryResourc use Extension\QueryColumnType; use DataObject\ClassDefinition\Data\Relations\AllowObjectRelationTrait; use DataObject\ClassDefinition\Data\Relations\ManyToManyRelationTrait; - + use DataObject\ClassDefinition\Data\Extension\RelationFilterConditionParser; /** * Static type of this element * @@ -874,4 +874,17 @@ public function addListingFilter(DataObject\Listing $listing, $data, $operator = return parent::addListingFilter($listing, $data, $operator); } + + /** + * Filter by relation feature + * @param array|string $value + * @param string $operator + * @param array $params + * @return string + */ + public function getFilterConditionExt($value, $operator, $params = []) + { + $name = $params['name'] ?: $this->name; + return $this->getRelationFilterCondition($value, $operator, $name); + } } diff --git a/models/DataObject/ClassDefinition/Data/ManyToManyRelation.php b/models/DataObject/ClassDefinition/Data/ManyToManyRelation.php index 442963052c1..0014febc363 100644 --- a/models/DataObject/ClassDefinition/Data/ManyToManyRelation.php +++ b/models/DataObject/ClassDefinition/Data/ManyToManyRelation.php @@ -31,7 +31,7 @@ class ManyToManyRelation extends AbstractRelations implements QueryResourcePersi use DataObject\ClassDefinition\Data\Relations\AllowAssetRelationTrait; use DataObject\ClassDefinition\Data\Relations\AllowDocumentRelationTrait; use DataObject\ClassDefinition\Data\Relations\ManyToManyRelationTrait; - + use DataObject\ClassDefinition\Data\Extension\RelationFilterConditionParser; /** * Static type of this element * @@ -942,4 +942,17 @@ public function addListingFilter(DataObject\Listing $listing, $data, $operator = throw new \InvalidArgumentException('Filtering '.__CLASS__.' does only support "=" operator'); } + + /** + * Filter by relation feature + * @param array|string $value + * @param string $operator + * @param array $params + * @return string + */ + public function getFilterConditionExt($value, $operator, $params = []) + { + $name = $params['name'] ?: $this->name; + return $this->getRelationFilterCondition($value, $operator, $name); + } } diff --git a/models/DataObject/ClassDefinition/Data/ManyToOneRelation.php b/models/DataObject/ClassDefinition/Data/ManyToOneRelation.php index d6a82ca6d8e..6a221b2c7e2 100644 --- a/models/DataObject/ClassDefinition/Data/ManyToOneRelation.php +++ b/models/DataObject/ClassDefinition/Data/ManyToOneRelation.php @@ -31,6 +31,7 @@ class ManyToOneRelation extends AbstractRelations implements QueryResourcePersis use DataObject\ClassDefinition\Data\Relations\AllowObjectRelationTrait; use DataObject\ClassDefinition\Data\Relations\AllowAssetRelationTrait; use DataObject\ClassDefinition\Data\Relations\AllowDocumentRelationTrait; + use DataObject\ClassDefinition\Data\Extension\RelationFilterConditionParser; /** * Static type of this element @@ -661,4 +662,17 @@ public function getPhpdocReturnType(): ?string return null; } + + /** + * Filter by relation feature + * @param array|string $value + * @param string $operator + * @param array $params + * @return string + */ + public function getFilterConditionExt($value, $operator, $params = []) + { + $name = $params['name'] . '__id'; + return $this->getRelationFilterCondition($value, $operator, $name); + } } From abbe9251ab0a55304231b6cd6398a09f7970ea86 Mon Sep 17 00:00:00 2001 From: fszenborn Date: Fri, 25 Jun 2021 15:47:07 +0200 Subject: [PATCH 02/16] Filter by relation on Grid - translations --- .../public/js/pimcore/element/helpers/gridColumnConfig.js | 8 ++++---- bundles/CoreBundle/Resources/translations/en.json | 8 ++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/element/helpers/gridColumnConfig.js b/bundles/AdminBundle/Resources/public/js/pimcore/element/helpers/gridColumnConfig.js index 8496f90674d..af0e686f05b 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/element/helpers/gridColumnConfig.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/element/helpers/gridColumnConfig.js @@ -332,7 +332,7 @@ pimcore.element.helpers.gridColumnConfig = { menu.add(batchRemoveSelectedMenu); var filterByRelationMenu = new Ext.menu.Item({ - text: t("Filter by relation"), + text: t("filter_by_relation"), iconCls: "pimcore_icon_filter pimcore_icon_overlay_add", handler: function (grid) { var menu = grid.headerCt.getMenu(); @@ -427,7 +427,7 @@ pimcore.element.helpers.gridColumnConfig = { bodyStyle: "padding: 10px;", buttons: [ { - text: t("Clear active relation filter"), + text: t("clear_relation_filter"), iconCls: "pimcore_icon_filter_condition pimcore_icon_overlay_delete", handler: function () { this.filterByRelationWindow.close(); @@ -435,7 +435,7 @@ pimcore.element.helpers.gridColumnConfig = { }.bind(this) }, { - text: t("Apply filter"), + text: t("apply_filter"), iconCls: "pimcore_icon_filter pimcore_icon_overlay_add", handler: function () { if (formPanel.isValid() && typeof fieldInfo.getRelationFilterCondition === "function") { @@ -455,7 +455,7 @@ pimcore.element.helpers.gridColumnConfig = { ] }); - var title = "Filter by relation field " + fieldInfo.text; + var title = t("filter_by_relation_field") + " " + fieldInfo.text; this.filterByRelationWindow = new Ext.Window({ autoScroll: true, modal: false, diff --git a/bundles/CoreBundle/Resources/translations/en.json b/bundles/CoreBundle/Resources/translations/en.json index 16a7dc8e24d..41ba7537d46 100644 --- a/bundles/CoreBundle/Resources/translations/en.json +++ b/bundles/CoreBundle/Resources/translations/en.json @@ -951,5 +951,9 @@ "save_draft": "Save draft", "selected_grid_columns": "Selected grid columns", "ungrouped": "ungrouped", - "reindex_warning": "Changing it from alphabetical sort order to index will reindex all items. Do you want to continue?" -} \ No newline at end of file + "reindex_warning": "Changing it from alphabetical sort order to index will reindex all items. Do you want to continue?", + "filter_by_relation": "Filter by relation", + "filter_by_relation_field": "Filter by relation field", + "clear_relation_filter": "Clear active relation filter", + "apply_filter": "Apply filter", +} From 87792b77d91149560773a8f3a46e4d4c96cac9b0 Mon Sep 17 00:00:00 2001 From: fszenborn Date: Mon, 28 Jun 2021 10:09:24 +0200 Subject: [PATCH 03/16] Filter by relation --- .../public/js/pimcore/element/helpers/gridColumnConfig.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/element/helpers/gridColumnConfig.js b/bundles/AdminBundle/Resources/public/js/pimcore/element/helpers/gridColumnConfig.js index af0e686f05b..53c19235cb8 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/element/helpers/gridColumnConfig.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/element/helpers/gridColumnConfig.js @@ -347,10 +347,10 @@ pimcore.element.helpers.gridColumnConfig = { var menu = grid.headerCt.getMenu(); var columnDataIndex = menu.activeHeader.dataIndex; - if (menu.activeHeader.config && typeof menu.activeHeader.config.getRelationFilter === "function") { - filterByRelationMenu.hide(); - } else { + if (menu.activeHeader.config && typeof menu.activeHeader.config.getRelationFilterCondition === "function") { filterByRelationMenu.show(); + } else { + filterByRelationMenu.hide(); } // no batch for system properties From 8eb75d623405f41f7d4818628b5c5f52a62462af Mon Sep 17 00:00:00 2001 From: fszenborn Date: Mon, 28 Jun 2021 12:28:29 +0200 Subject: [PATCH 04/16] Filter by relation on Grid --- .../Data/Extension/RelationFilterConditionParser.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/models/DataObject/ClassDefinition/Data/Extension/RelationFilterConditionParser.php b/models/DataObject/ClassDefinition/Data/Extension/RelationFilterConditionParser.php index 30858589412..24948c76952 100644 --- a/models/DataObject/ClassDefinition/Data/Extension/RelationFilterConditionParser.php +++ b/models/DataObject/ClassDefinition/Data/Extension/RelationFilterConditionParser.php @@ -28,7 +28,7 @@ public function getRelationFilterCondition($value, $operator, $name) return '`' . $name . '` LIKE ' . $value . ' '; } elseif ($operator == 'LIKE') { $result = $name . " IS NULL"; - $values = explode(',', $value ?? ''); + $values = explode(',', (string)$value ?? ''); if (is_array($values) && !empty($values)) { $fieldConditions = []; foreach ($values as $value) { @@ -43,6 +43,5 @@ public function getRelationFilterCondition($value, $operator, $name) } return $result; } - return "1=1"; } } From 3b8df8a416a24681ed519a880227255d64860cc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20P=C5=82askonka?= Date: Fri, 3 Sep 2021 22:49:32 +0200 Subject: [PATCH 05/16] Fix for non-editable relations --- .../public/js/pimcore/element/helpers/gridColumnConfig.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/element/helpers/gridColumnConfig.js b/bundles/AdminBundle/Resources/public/js/pimcore/element/helpers/gridColumnConfig.js index 53c19235cb8..03069d18a66 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/element/helpers/gridColumnConfig.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/element/helpers/gridColumnConfig.js @@ -406,11 +406,6 @@ pimcore.element.helpers.gridColumnConfig = { return; } - if (fieldInfo.layout.layout.noteditable) { - Ext.MessageBox.alert(t('error'), t('this_element_cannot_be_edited')); - return; - } - var tagType = fieldInfo.layout.type; var editor = new pimcore.object.tags[tagType](null, fieldInfo.layout.layout); editor.setObject(this.object); From 14cd403ed134f0f5cf0ac7e977d5bb29fac00f45 Mon Sep 17 00:00:00 2001 From: fszenborn Date: Mon, 27 Sep 2021 17:42:44 +0200 Subject: [PATCH 06/16] Gridfilter on relation fields - codestylefix --- .../RelationFilterConditionParser.php | 35 ++++++++----------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/models/DataObject/ClassDefinition/Data/Extension/RelationFilterConditionParser.php b/models/DataObject/ClassDefinition/Data/Extension/RelationFilterConditionParser.php index 24948c76952..c5c27de11fb 100644 --- a/models/DataObject/ClassDefinition/Data/Extension/RelationFilterConditionParser.php +++ b/models/DataObject/ClassDefinition/Data/Extension/RelationFilterConditionParser.php @@ -16,32 +16,27 @@ trait RelationFilterConditionParser { /** * Parses filter value of a relation field and creates the filter condition - * @param $value - * @param $operator - * @param $name + * @param string $value + * @param string $operator + * @param string $name * @return string */ public function getRelationFilterCondition($value, $operator, $name) { if ($operator == '=') { - $value = "'%," . $value . ",%'"; - return '`' . $name . '` LIKE ' . $value . ' '; - } elseif ($operator == 'LIKE') { - $result = $name . " IS NULL"; - $values = explode(',', (string)$value ?? ''); - if (is_array($values) && !empty($values)) { - $fieldConditions = []; - foreach ($values as $value) { - if (empty($value)) { - continue; - } - $fieldConditions[] = '`' . $name . "` LIKE '%" . $value . "%' "; - } - if (!empty($fieldConditions)) { - $result = '(' . implode(' AND ', $fieldConditions) . ')'; - } + return '`' . $name . '` LIKE ' . "'%," . $value . ",%'"; + } + $result = $name . " IS NULL"; + $values = explode(',', (string)$value ?? ''); + if (is_array($values) && !empty($values)) { + $fieldConditions = array_map(function ($value) use ($name) { + return '`' . $name . "` LIKE '%" . $value . "%' "; + }, array_filter($values)); + if (!empty($fieldConditions)) { + $result = '(' . implode(' AND ', $fieldConditions) . ')'; } - return $result; } + + return $result; } } From 5b59890238d8dd8ac8ce420d51cce6baf8f1acf7 Mon Sep 17 00:00:00 2001 From: fszenborn Date: Mon, 27 Sep 2021 18:12:14 +0200 Subject: [PATCH 07/16] Gridfilter on relation fields - map insteadof foreach --- .../object/tags/advancedManyToManyRelation.js | 11 ++++------- .../pimcore/object/tags/manyToManyObjectRelation.js | 12 +++++------- .../js/pimcore/object/tags/manyToManyRelation.js | 8 +++----- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/advancedManyToManyRelation.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/advancedManyToManyRelation.js index 8c5d3293f91..0908cc840a7 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/advancedManyToManyRelation.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/advancedManyToManyRelation.js @@ -947,15 +947,12 @@ pimcore.object.tags.advancedManyToManyRelation = Class.create(pimcore.object.tag }, getRelationFilterCondition: function (editor) { - var filterResult = []; - editor.store.getData().items.forEach( + var filterResult = editor.store.getData().items.map( function (item) { - filterResult.push(item.data.type + "|" + item.data.id); - } - ); - filterResult = filterResult.join(','); + return item.data.type + "|" + item.data.id; + }); - return filterResult; + return filterResult.join(','); }, getCellEditValue: function () { diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyObjectRelation.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyObjectRelation.js index 6e5f5b11064..dce4062881c 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyObjectRelation.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyObjectRelation.js @@ -94,14 +94,12 @@ pimcore.object.tags.manyToManyObjectRelation = Class.create(pimcore.object.tags. }, getRelationFilterCondition: function (editor) { - var filterResult = []; - editor.store.getData().items.forEach( - function (item) { - filterResult.push(item.data.id); - }); - filterResult = filterResult.join(','); + var filterResult = editor.store.getData().items.map( + function (item) { + return item.data.id; + }); - return filterResult; + return filterResult.join(','); }, openParentSearchEditor: function () { diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyRelation.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyRelation.js index 6a5ea1356fe..df6e253df63 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyRelation.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyRelation.js @@ -102,14 +102,12 @@ pimcore.object.tags.manyToManyRelation = Class.create(pimcore.object.tags.abstra }, getRelationFilterCondition: function (editor) { - var filterResult = []; - editor.store.getData().items.forEach( + var filterResult = editor.store.getData().items.map( function (item) { - filterResult.push(item.data.type + "|" + item.data.id); + return item.data.type + "|" + item.data.id; }); - filterResult = filterResult.join(','); - return filterResult; + return filterResult.join(','); }, getLayoutEdit: function () { From 8b8e3962ee76980852d25241df59f2578c6542a6 Mon Sep 17 00:00:00 2001 From: fszenborn Date: Tue, 19 Oct 2021 15:13:58 +0200 Subject: [PATCH 08/16] Gridfilter on relation fields - fixes after review --- .../element/helpers/gridColumnConfig.js | 10 ++------- .../tags/advancedManyToManyObjectRelation.js | 2 +- .../object/tags/advancedManyToManyRelation.js | 16 +++++++++----- .../js/pimcore/object/tags/hotspotimage.js | 17 ++++++++++---- .../public/js/pimcore/object/tags/image.js | 17 ++++++++++---- .../object/tags/manyToManyObjectRelation.js | 16 +++++++++----- .../pimcore/object/tags/manyToManyRelation.js | 22 ++++++++++++------- .../pimcore/object/tags/manyToOneRelation.js | 16 ++++++++++---- .../RelationFilterConditionParser.php | 4 ++-- .../Data/ManyToOneRelation.php | 8 +++++++ 10 files changed, 87 insertions(+), 41 deletions(-) diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/element/helpers/gridColumnConfig.js b/bundles/AdminBundle/Resources/public/js/pimcore/element/helpers/gridColumnConfig.js index 03069d18a66..f7e7b3dcdd9 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/element/helpers/gridColumnConfig.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/element/helpers/gridColumnConfig.js @@ -433,15 +433,9 @@ pimcore.element.helpers.gridColumnConfig = { text: t("apply_filter"), iconCls: "pimcore_icon_filter pimcore_icon_overlay_add", handler: function () { - if (formPanel.isValid() && typeof fieldInfo.getRelationFilterCondition === "function") { + if (formPanel.isValid() && typeof fieldInfo.getRelationFilter === "function") { this.grid.filters.getStore().addFilter( - new Ext.util.Filter({ - operator: "like", - type: "string", - id: "x-gridfilter-" + fieldInfo.dataIndex, - property: fieldInfo.dataIndex, - value: fieldInfo.getRelationFilterCondition(editor) - }) + fieldInfo.getRelationFilter(fieldInfo.dataIndex, editor) ); this.filterByRelationWindow.close(); } diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/advancedManyToManyObjectRelation.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/advancedManyToManyObjectRelation.js index d44a3609de9..72ec7260b30 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/advancedManyToManyObjectRelation.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/advancedManyToManyObjectRelation.js @@ -599,7 +599,7 @@ pimcore.object.tags.advancedManyToManyObjectRelation = Class.create(pimcore.obje return { text: t(field.label), width: 150, sortable: false, dataIndex: field.key, getEditor: this.getWindowCellEditor.bind(this, field), - getRelationFilterCondition: this.getRelationFilterCondition, + getRelationFilter: this.getRelationFilter, renderer: pimcore.object.helpers.grid.prototype.advancedRelationGridRenderer.bind(this, field, "fullpath") }; }, diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/advancedManyToManyRelation.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/advancedManyToManyRelation.js index 0908cc840a7..1fbcf272d23 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/advancedManyToManyRelation.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/advancedManyToManyRelation.js @@ -941,18 +941,24 @@ pimcore.object.tags.advancedManyToManyRelation = Class.create(pimcore.object.tag return { text: t(field.label), width: 150, sortable: false, dataIndex: field.key, getEditor: this.getWindowCellEditor.bind(this, field), - getRelationFilterCondition: this.getRelationFilterCondition, + getRelationFilter: this.getRelationFilter, renderer: pimcore.object.helpers.grid.prototype.advancedRelationGridRenderer.bind(this, field, "path"), }; }, - getRelationFilterCondition: function (editor) { - var filterResult = editor.store.getData().items.map( + getRelationFilter: function (dataIndex, editor) { + var filterValues = editor.store.getData().items.map( function (item) { return item.data.type + "|" + item.data.id; }); - - return filterResult.join(','); + return new Ext.util.Filter({ + operator: "like", + type: "string", + id: "x-gridfilter-" + dataIndex, + property: dataIndex, + dataIndex: dataIndex, + value: filterValues.join(','); + }); }, getCellEditValue: function () { diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/hotspotimage.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/hotspotimage.js index 86cb12a481b..1bf1477c1b2 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/hotspotimage.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/hotspotimage.js @@ -54,10 +54,7 @@ pimcore.object.tags.hotspotimage = Class.create(pimcore.object.tags.image, { return { text: t(field.label), width: 100, sortable: false, dataIndex: field.key, getEditor: this.getWindowCellEditor.bind(this, field), - getRelationFilterCondition: function(editor) { - var filterResult = editor.data ? editor.data.id : null; - return filterResult; - }, + getRelationFilter: this.getRelationFilter, renderer: function (key, value, metaData, record, rowIndex, colIndex, store, view) { this.applyPermissionStyle(key, value, metaData, record); @@ -96,6 +93,18 @@ pimcore.object.tags.hotspotimage = Class.create(pimcore.object.tags.image, { }; }, + getRelationFilter: function (dataIndex, editor) { + var filterValue = editor.data ? editor.data.id : null; + return new Ext.util.Filter({ + operator: "=", + type: "string", + id: "x-gridfilter-" + dataIndex, + property: dataIndex, + dataIndex: dataIndex, + value: filterValue + }); + }, + getLayoutEdit: function () { if (intval(this.fieldConfig.width) < 1) { diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/image.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/image.js index 2a7fe28d192..dd98c8904d4 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/image.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/image.js @@ -32,10 +32,7 @@ pimcore.object.tags.image = Class.create(pimcore.object.tags.abstract, { return { text: t(field.label), width: 100, sortable: false, dataIndex: field.key, getEditor: this.getWindowCellEditor.bind(this, field), - getRelationFilterCondition: function(editor) { - var filterResult = editor.data ? editor.data.id : null; - return filterResult; - }, + getRelationFilter: this.getRelationFilter, renderer: function (key, value, metaData, record, rowIndex, colIndex, store, view) { this.applyPermissionStyle(key, value, metaData, record); @@ -71,6 +68,18 @@ pimcore.object.tags.image = Class.create(pimcore.object.tags.abstract, { }; }, + getRelationFilter: function (dataIndex, editor) { + var filterValue = editor.data ? editor.data.id : null; + return new Ext.util.Filter({ + operator: "=", + type: "string", + id: "x-gridfilter-" + dataIndex, + property: dataIndex, + dataIndex: dataIndex, + value: filterValue + }); + }, + getLayoutEdit: function () { if (!this.fieldConfig.width) { this.fieldConfig.width = 300; diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyObjectRelation.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyObjectRelation.js index dce4062881c..268967724e2 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyObjectRelation.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyObjectRelation.js @@ -88,18 +88,24 @@ pimcore.object.tags.manyToManyObjectRelation = Class.create(pimcore.object.tags. return result.join("
"); } }.bind(this, field.key), - getRelationFilterCondition: this.getRelationFilterCondition, + getRelationFilter: this.getRelationFilter, getEditor: this.getWindowCellEditor.bind(this, field) }; }, - getRelationFilterCondition: function (editor) { - var filterResult = editor.store.getData().items.map( + getRelationFilter: function (dataIndex, editor) { + var filterValues = editor.store.getData().items.map( function (item) { return item.data.id; }); - - return filterResult.join(','); + return new Ext.util.Filter({ + operator: "like", + type: "string", + id: "x-gridfilter-" + dataIndex, + property: dataIndex, + dataIndex: dataIndex, + value: filterValues.join(','); + }); }, openParentSearchEditor: function () { diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyRelation.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyRelation.js index df6e253df63..ed1a9936646 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyRelation.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyRelation.js @@ -76,7 +76,7 @@ pimcore.object.tags.manyToManyRelation = Class.create(pimcore.object.tags.abstra return { text: t(field.label), width: 150, sortable: false, dataIndex: field.key, getEditor: this.getWindowCellEditor.bind(this, field), - getRelationFilterCondition: this.getRelationFilterCondition, + getRelationFilter: this.getRelationFilter, renderer: function (key, value, metaData, record) { this.applyPermissionStyle(key, value, metaData, record); @@ -101,13 +101,19 @@ pimcore.object.tags.manyToManyRelation = Class.create(pimcore.object.tags.abstra }; }, - getRelationFilterCondition: function (editor) { - var filterResult = editor.store.getData().items.map( - function (item) { - return item.data.type + "|" + item.data.id; - }); - - return filterResult.join(','); + getRelationFilter: function (dataIndex, editor) { + var filterValues = editor.store.getData().items.map( + function (item) { + return item.data.type + "|" + item.data.id; + }); + return new Ext.util.Filter({ + operator: "like", + type: "string", + id: "x-gridfilter-" + dataIndex, + property: dataIndex, + dataIndex: dataIndex, + value: filterValues.join(','); + }); }, getLayoutEdit: function () { diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToOneRelation.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToOneRelation.js index bf987935641..221a27b4464 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToOneRelation.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToOneRelation.js @@ -55,14 +55,22 @@ pimcore.object.tags.manyToOneRelation = Class.create(pimcore.object.tags.abstrac return { text: t(field.label), sortable: false, dataIndex: field.key, renderer: renderer, - getRelationFilterCondition: function(editor) { - var filterResult = editor.data ? editor.data.id : null; - return filterResult; - }, + getRelationFilter: this.getRelationFilter, getEditor: this.getWindowCellEditor.bind(this, field) }; }, + getRelationFilter: function (dataIndex, editor) { + var filterValue = editor.data ? editor.data.type + "|" + editor.data.id : null; + return new Ext.util.Filter({ + operator: "=", + type: "string", + id: "x-gridfilter-" + dataIndex, + property: dataIndex, + dataIndex: dataIndex, + value: filterValue + }); + }, getLayoutEdit: function () { diff --git a/models/DataObject/ClassDefinition/Data/Extension/RelationFilterConditionParser.php b/models/DataObject/ClassDefinition/Data/Extension/RelationFilterConditionParser.php index c5c27de11fb..2d8f179dc3f 100644 --- a/models/DataObject/ClassDefinition/Data/Extension/RelationFilterConditionParser.php +++ b/models/DataObject/ClassDefinition/Data/Extension/RelationFilterConditionParser.php @@ -24,13 +24,13 @@ trait RelationFilterConditionParser public function getRelationFilterCondition($value, $operator, $name) { if ($operator == '=') { - return '`' . $name . '` LIKE ' . "'%," . $value . ",%'"; + return '`' . $name . '` = ' . "'" . $value . "'"; } $result = $name . " IS NULL"; $values = explode(',', (string)$value ?? ''); if (is_array($values) && !empty($values)) { $fieldConditions = array_map(function ($value) use ($name) { - return '`' . $name . "` LIKE '%" . $value . "%' "; + return '`' . $name . "` LIKE '%," . $value . ",%' "; }, array_filter($values)); if (!empty($fieldConditions)) { $result = '(' . implode(' AND ', $fieldConditions) . ')'; diff --git a/models/DataObject/ClassDefinition/Data/ManyToOneRelation.php b/models/DataObject/ClassDefinition/Data/ManyToOneRelation.php index 6a221b2c7e2..01ce822cee3 100644 --- a/models/DataObject/ClassDefinition/Data/ManyToOneRelation.php +++ b/models/DataObject/ClassDefinition/Data/ManyToOneRelation.php @@ -673,6 +673,14 @@ public function getPhpdocReturnType(): ?string public function getFilterConditionExt($value, $operator, $params = []) { $name = $params['name'] . '__id'; + if (preg_match('/^(asset|object|document)\|(\d+)/', $value, $matches)) { + $typeField = $params['name'] . '__type'; + $typeCondition = '`' . $typeField . '` = ' . "'" . $matches[1] . "'"; + $value = $matches[2]; + + return '(' . $typeCondition . ' AND ' . $this->getRelationFilterCondition($value, $operator, $name) . ')'; + } + return $this->getRelationFilterCondition($value, $operator, $name); } } From bf3671fb57554cb795447ee624145b929af8abdb Mon Sep 17 00:00:00 2001 From: fszenborn Date: Wed, 20 Oct 2021 07:43:21 +0200 Subject: [PATCH 09/16] Gridfilter on relation fields - fixes after review --- .../public/js/pimcore/object/tags/advancedManyToManyRelation.js | 2 +- .../public/js/pimcore/object/tags/manyToManyObjectRelation.js | 2 +- .../public/js/pimcore/object/tags/manyToManyRelation.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/advancedManyToManyRelation.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/advancedManyToManyRelation.js index ef35330e493..345e1bc80e5 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/advancedManyToManyRelation.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/advancedManyToManyRelation.js @@ -956,7 +956,7 @@ pimcore.object.tags.advancedManyToManyRelation = Class.create(pimcore.object.tag id: "x-gridfilter-" + dataIndex, property: dataIndex, dataIndex: dataIndex, - value: filterValues.join(','); + value: filterValues.join(',') }); }, diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyObjectRelation.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyObjectRelation.js index 8ce40183f23..f427bbfcef1 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyObjectRelation.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyObjectRelation.js @@ -104,7 +104,7 @@ pimcore.object.tags.manyToManyObjectRelation = Class.create(pimcore.object.tags. id: "x-gridfilter-" + dataIndex, property: dataIndex, dataIndex: dataIndex, - value: filterValues.join(','); + value: filterValues.join(',') }); }, diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyRelation.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyRelation.js index 3475ff45056..f157046f4f8 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyRelation.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyRelation.js @@ -112,7 +112,7 @@ pimcore.object.tags.manyToManyRelation = Class.create(pimcore.object.tags.abstra id: "x-gridfilter-" + dataIndex, property: dataIndex, dataIndex: dataIndex, - value: filterValues.join(','); + value: filterValues.join(',') }); }, From 5aca346350aa2277049753326a9101e461d196a9 Mon Sep 17 00:00:00 2001 From: fszenborn Date: Wed, 20 Oct 2021 11:03:44 +0200 Subject: [PATCH 10/16] Gridfilter on relation fields - fixes after review --- .../public/js/pimcore/element/helpers/gridColumnConfig.js | 2 +- .../public/js/pimcore/object/helpers/gridTabAbstract.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/element/helpers/gridColumnConfig.js b/bundles/AdminBundle/Resources/public/js/pimcore/element/helpers/gridColumnConfig.js index 7a16bfa3589..114ce787d5e 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/element/helpers/gridColumnConfig.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/element/helpers/gridColumnConfig.js @@ -347,7 +347,7 @@ pimcore.element.helpers.gridColumnConfig = { var menu = grid.headerCt.getMenu(); var columnDataIndex = menu.activeHeader.dataIndex; - if (menu.activeHeader.config && typeof menu.activeHeader.config.getRelationFilterCondition === "function") { + if (menu.activeHeader.config && typeof menu.activeHeader.config.getRelationFilter === "function") { filterByRelationMenu.show(); } else { filterByRelationMenu.hide(); diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/helpers/gridTabAbstract.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/helpers/gridTabAbstract.js index 7ca3a6c79f4..63b288f5a6b 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/helpers/gridTabAbstract.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/helpers/gridTabAbstract.js @@ -207,7 +207,7 @@ pimcore.object.helpers.gridTabAbstract = Class.create({ } ); - this.grid.getStore().clearFilter() + this.grid.getStore().clearFilter(); this.grid.filters.clearFilters(); this.pagingtoolbar.moveFirst(); @@ -233,7 +233,7 @@ pimcore.object.helpers.gridTabAbstract = Class.create({ ); proxy.setExtraParam("condition", this.sqlEditor.getValue()); if (this.grid && this.grid.filters) { - this.grid.getStore().clearFilter() + this.grid.getStore().clearFilter(); this.grid.filters.clearFilters(); } @@ -297,7 +297,7 @@ pimcore.object.helpers.gridTabAbstract = Class.create({ text: t("clear_filters"), tooltip: t("clear_filters"), handler: function (button) { - this.grid.getStore().clearFilter() + this.grid.getStore().clearFilter(); this.grid.filters.clearFilters(); this.toolbarFilterInfo.hide(); this.clearFilterButton.hide(); @@ -315,8 +315,8 @@ pimcore.object.helpers.gridTabAbstract = Class.create({ listeners: { "change": function (field, checked) { this.grid.getStore().setRemoteFilter(false); + this.grid.getStore().clearFilter(); this.grid.filters.clearFilters(); - this.grid.getStore().clearFilter() this.store.getProxy().setExtraParam("only_direct_children", checked); From 02ddcc3f6e9b515a312bc8f01e2e5f9e4c5c5493 Mon Sep 17 00:00:00 2001 From: fszenborn Date: Wed, 20 Oct 2021 12:43:40 +0200 Subject: [PATCH 11/16] Gridfilter on relation fields - fixes after review --- .../object/tags/advancedManyToManyRelation.js | 13 +++++++++---- .../public/js/pimcore/object/tags/hotspotimage.js | 2 +- .../public/js/pimcore/object/tags/image.js | 2 +- .../pimcore/object/tags/manyToManyObjectRelation.js | 13 +++++++++---- .../js/pimcore/object/tags/manyToManyRelation.js | 13 +++++++++---- .../js/pimcore/object/tags/manyToOneRelation.js | 2 +- .../Extension/RelationFilterConditionParser.php | 5 ++++- 7 files changed, 34 insertions(+), 16 deletions(-) diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/advancedManyToManyRelation.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/advancedManyToManyRelation.js index 345e1bc80e5..211e8c761d9 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/advancedManyToManyRelation.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/advancedManyToManyRelation.js @@ -946,17 +946,22 @@ pimcore.object.tags.advancedManyToManyRelation = Class.create(pimcore.object.tag }, getRelationFilter: function (dataIndex, editor) { - var filterValues = editor.store.getData().items.map( - function (item) { + var filterValues = editor.store.getData().items; + if (!filterValues || !Array.isArray(filterValues) || !filterValues.length) { + filterValues = null; + } else { + filterValues = filterValues.map(function (item) { return item.data.type + "|" + item.data.id; - }); + }).join(','); + } + return new Ext.util.Filter({ operator: "like", type: "string", id: "x-gridfilter-" + dataIndex, property: dataIndex, dataIndex: dataIndex, - value: filterValues.join(',') + value: filterValues }); }, diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/hotspotimage.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/hotspotimage.js index f4e6a9bc616..9fee237d558 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/hotspotimage.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/hotspotimage.js @@ -94,7 +94,7 @@ pimcore.object.tags.hotspotimage = Class.create(pimcore.object.tags.image, { }, getRelationFilter: function (dataIndex, editor) { - var filterValue = editor.data ? editor.data.id : null; + var filterValue = editor.data && editor.data.id !== undefined ? editor.data.id : null; return new Ext.util.Filter({ operator: "=", type: "string", diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/image.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/image.js index 9ed8a62387e..f1e8fd17dc3 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/image.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/image.js @@ -69,7 +69,7 @@ pimcore.object.tags.image = Class.create(pimcore.object.tags.abstract, { }, getRelationFilter: function (dataIndex, editor) { - var filterValue = editor.data ? editor.data.id : null; + var filterValue = editor.data && editor.data.id !== undefined ? editor.data.id : null; return new Ext.util.Filter({ operator: "=", type: "string", diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyObjectRelation.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyObjectRelation.js index f427bbfcef1..79ab8a0415a 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyObjectRelation.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyObjectRelation.js @@ -94,17 +94,22 @@ pimcore.object.tags.manyToManyObjectRelation = Class.create(pimcore.object.tags. }, getRelationFilter: function (dataIndex, editor) { - var filterValues = editor.store.getData().items.map( - function (item) { + var filterValues = editor.store.getData().items; + if (!filterValues || !Array.isArray(filterValues) || !filterValues.length) { + filterValues = null; + } else { + filterValues = filterValues.map(function (item) { return item.data.id; - }); + }).join(','); + } + return new Ext.util.Filter({ operator: "like", type: "string", id: "x-gridfilter-" + dataIndex, property: dataIndex, dataIndex: dataIndex, - value: filterValues.join(',') + value: filterValues }); }, diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyRelation.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyRelation.js index f157046f4f8..fecbb96c3c0 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyRelation.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToManyRelation.js @@ -102,17 +102,22 @@ pimcore.object.tags.manyToManyRelation = Class.create(pimcore.object.tags.abstra }, getRelationFilter: function (dataIndex, editor) { - var filterValues = editor.store.getData().items.map( - function (item) { + var filterValues = editor.store.getData().items; + if (!filterValues || !Array.isArray(filterValues) || !filterValues.length) { + filterValues = null; + } else { + filterValues = filterValues.map(function (item) { return item.data.type + "|" + item.data.id; - }); + }).join(','); + } + return new Ext.util.Filter({ operator: "like", type: "string", id: "x-gridfilter-" + dataIndex, property: dataIndex, dataIndex: dataIndex, - value: filterValues.join(',') + value: filterValues }); }, diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToOneRelation.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToOneRelation.js index 221a27b4464..d7f02a4cad9 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToOneRelation.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToOneRelation.js @@ -61,7 +61,7 @@ pimcore.object.tags.manyToOneRelation = Class.create(pimcore.object.tags.abstrac }, getRelationFilter: function (dataIndex, editor) { - var filterValue = editor.data ? editor.data.type + "|" + editor.data.id : null; + var filterValue = editor.data && editor.data.id !== undefined ? editor.data.type + "|" + editor.data.id : null; return new Ext.util.Filter({ operator: "=", type: "string", diff --git a/models/DataObject/ClassDefinition/Data/Extension/RelationFilterConditionParser.php b/models/DataObject/ClassDefinition/Data/Extension/RelationFilterConditionParser.php index 2d8f179dc3f..c8f7fb49d56 100644 --- a/models/DataObject/ClassDefinition/Data/Extension/RelationFilterConditionParser.php +++ b/models/DataObject/ClassDefinition/Data/Extension/RelationFilterConditionParser.php @@ -23,10 +23,13 @@ trait RelationFilterConditionParser */ public function getRelationFilterCondition($value, $operator, $name) { + $result = '`' . $name . "` IS NULL"; + if ($value === null) { + return $result; + } if ($operator == '=') { return '`' . $name . '` = ' . "'" . $value . "'"; } - $result = $name . " IS NULL"; $values = explode(',', (string)$value ?? ''); if (is_array($values) && !empty($values)) { $fieldConditions = array_map(function ($value) use ($name) { From 3fdf37a8b8d8686f3361e2ec6b57c5b1ef12c1cc Mon Sep 17 00:00:00 2001 From: fszenborn Date: Wed, 20 Oct 2021 12:57:41 +0200 Subject: [PATCH 12/16] Gridfilter on relation fields - fixes after review --- .../Data/Extension/RelationFilterConditionParser.php | 6 +++--- models/DataObject/ClassDefinition/Data/Hotspotimage.php | 6 +++--- models/DataObject/ClassDefinition/Data/Image.php | 6 +++--- .../ClassDefinition/Data/ManyToManyObjectRelation.php | 6 +++--- .../DataObject/ClassDefinition/Data/ManyToManyRelation.php | 6 +++--- .../DataObject/ClassDefinition/Data/ManyToOneRelation.php | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/models/DataObject/ClassDefinition/Data/Extension/RelationFilterConditionParser.php b/models/DataObject/ClassDefinition/Data/Extension/RelationFilterConditionParser.php index c8f7fb49d56..3448764efd7 100644 --- a/models/DataObject/ClassDefinition/Data/Extension/RelationFilterConditionParser.php +++ b/models/DataObject/ClassDefinition/Data/Extension/RelationFilterConditionParser.php @@ -16,9 +16,9 @@ trait RelationFilterConditionParser { /** * Parses filter value of a relation field and creates the filter condition - * @param string $value - * @param string $operator - * @param string $name + * @param string|null $value + * @param string $operator + * @param string $name * @return string */ public function getRelationFilterCondition($value, $operator, $name) diff --git a/models/DataObject/ClassDefinition/Data/Hotspotimage.php b/models/DataObject/ClassDefinition/Data/Hotspotimage.php index 82feba3e44c..270f37e7ba4 100644 --- a/models/DataObject/ClassDefinition/Data/Hotspotimage.php +++ b/models/DataObject/ClassDefinition/Data/Hotspotimage.php @@ -692,9 +692,9 @@ public function denormalize($value, $params = []) /** * Filter by relation feature - * @param array|string $value - * @param string $operator - * @param array $params + * @param array|string|null $value + * @param string $operator + * @param array $params * @return string */ public function getFilterConditionExt($value, $operator, $params = []) diff --git a/models/DataObject/ClassDefinition/Data/Image.php b/models/DataObject/ClassDefinition/Data/Image.php index 39c1dc7ecdf..a4810f13625 100644 --- a/models/DataObject/ClassDefinition/Data/Image.php +++ b/models/DataObject/ClassDefinition/Data/Image.php @@ -380,9 +380,9 @@ public function denormalize($value, $params = []) /** * Filter by relation feature - * @param array|string $value - * @param string $operator - * @param array $params + * @param array|string|null $value + * @param string $operator + * @param array $params * @return string */ public function getFilterConditionExt($value, $operator, $params = []) diff --git a/models/DataObject/ClassDefinition/Data/ManyToManyObjectRelation.php b/models/DataObject/ClassDefinition/Data/ManyToManyObjectRelation.php index a1a29477375..97867848f38 100644 --- a/models/DataObject/ClassDefinition/Data/ManyToManyObjectRelation.php +++ b/models/DataObject/ClassDefinition/Data/ManyToManyObjectRelation.php @@ -903,9 +903,9 @@ public function addListingFilter(DataObject\Listing $listing, $data, $operator = /** * Filter by relation feature - * @param array|string $value - * @param string $operator - * @param array $params + * @param array|string|null $value + * @param string $operator + * @param array $params * @return string */ public function getFilterConditionExt($value, $operator, $params = []) diff --git a/models/DataObject/ClassDefinition/Data/ManyToManyRelation.php b/models/DataObject/ClassDefinition/Data/ManyToManyRelation.php index 388f51b3f3b..692f5e607ff 100644 --- a/models/DataObject/ClassDefinition/Data/ManyToManyRelation.php +++ b/models/DataObject/ClassDefinition/Data/ManyToManyRelation.php @@ -973,9 +973,9 @@ public function addListingFilter(DataObject\Listing $listing, $data, $operator = /** * Filter by relation feature - * @param array|string $value - * @param string $operator - * @param array $params + * @param array|string|null $value + * @param string $operator + * @param array $params * @return string */ public function getFilterConditionExt($value, $operator, $params = []) diff --git a/models/DataObject/ClassDefinition/Data/ManyToOneRelation.php b/models/DataObject/ClassDefinition/Data/ManyToOneRelation.php index 69ed37e49fb..c9ce6b015ee 100644 --- a/models/DataObject/ClassDefinition/Data/ManyToOneRelation.php +++ b/models/DataObject/ClassDefinition/Data/ManyToOneRelation.php @@ -669,9 +669,9 @@ public function getPhpdocReturnType(): ?string /** * Filter by relation feature - * @param array|string $value - * @param string $operator - * @param array $params + * @param array|string|null $value + * @param string $operator + * @param array $params * @return string */ public function getFilterConditionExt($value, $operator, $params = []) From 18c684f5451bdbb855185a315b35699992c6cda8 Mon Sep 17 00:00:00 2001 From: fszenborn Date: Wed, 20 Oct 2021 14:36:51 +0200 Subject: [PATCH 13/16] Gridfilter on relation fields - fixes after review --- bundles/AdminBundle/Controller/Admin/ElementController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bundles/AdminBundle/Controller/Admin/ElementController.php b/bundles/AdminBundle/Controller/Admin/ElementController.php index b795622cc6c..217786d6a6a 100644 --- a/bundles/AdminBundle/Controller/Admin/ElementController.php +++ b/bundles/AdminBundle/Controller/Admin/ElementController.php @@ -892,7 +892,7 @@ protected function getNicePathFormatterFieldDefinition($source, $context) } /** - * @param DataObject\Concrete $source + * @param Element\AbstractElement $source * @param array $context * @param array $result * @param array $targets @@ -901,7 +901,7 @@ protected function getNicePathFormatterFieldDefinition($source, $context) * * @throws \Exception */ - protected function convertResultWithPathFormatter(DataObject\Concrete $source, $context, $result, $targets): array + protected function convertResultWithPathFormatter(Element\AbstractElement $source, $context, $result, $targets): array { $fd = $this->getNicePathFormatterFieldDefinition($source, $context); From cc54a86ffa8c82a417e193c749f8a6e1d952ba78 Mon Sep 17 00:00:00 2001 From: fszenborn Date: Wed, 20 Oct 2021 14:36:59 +0200 Subject: [PATCH 14/16] Gridfilter on relation fields - fixes after review --- .../Resources/public/js/pimcore/object/tags/hotspotimage.js | 2 +- .../Resources/public/js/pimcore/object/tags/image.js | 2 +- .../public/js/pimcore/object/tags/manyToOneRelation.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/hotspotimage.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/hotspotimage.js index 9fee237d558..e38411bceff 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/hotspotimage.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/hotspotimage.js @@ -97,7 +97,7 @@ pimcore.object.tags.hotspotimage = Class.create(pimcore.object.tags.image, { var filterValue = editor.data && editor.data.id !== undefined ? editor.data.id : null; return new Ext.util.Filter({ operator: "=", - type: "string", + type: "int", id: "x-gridfilter-" + dataIndex, property: dataIndex, dataIndex: dataIndex, diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/image.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/image.js index f1e8fd17dc3..3ffac32eb57 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/image.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/image.js @@ -72,7 +72,7 @@ pimcore.object.tags.image = Class.create(pimcore.object.tags.abstract, { var filterValue = editor.data && editor.data.id !== undefined ? editor.data.id : null; return new Ext.util.Filter({ operator: "=", - type: "string", + type: "int", id: "x-gridfilter-" + dataIndex, property: dataIndex, dataIndex: dataIndex, diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToOneRelation.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToOneRelation.js index d7f02a4cad9..739d08dc87d 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToOneRelation.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/manyToOneRelation.js @@ -64,7 +64,7 @@ pimcore.object.tags.manyToOneRelation = Class.create(pimcore.object.tags.abstrac var filterValue = editor.data && editor.data.id !== undefined ? editor.data.type + "|" + editor.data.id : null; return new Ext.util.Filter({ operator: "=", - type: "string", + type: "int", id: "x-gridfilter-" + dataIndex, property: dataIndex, dataIndex: dataIndex, From a7e8247f7b831cd48025a5beb5a33d9d40b68da7 Mon Sep 17 00:00:00 2001 From: fszenborn Date: Fri, 29 Oct 2021 09:33:24 +0200 Subject: [PATCH 15/16] CS Update models/DataObject/ClassDefinition/Data/Extension/RelationFilterConditionParser.php coding standard update Co-authored-by: Divesh Pahuja --- .../Extension/RelationFilterConditionParser.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/models/DataObject/ClassDefinition/Data/Extension/RelationFilterConditionParser.php b/models/DataObject/ClassDefinition/Data/Extension/RelationFilterConditionParser.php index 3448764efd7..74d0df8903b 100644 --- a/models/DataObject/ClassDefinition/Data/Extension/RelationFilterConditionParser.php +++ b/models/DataObject/ClassDefinition/Data/Extension/RelationFilterConditionParser.php @@ -1,10 +1,18 @@ + * Pimcore + * + * This source file is available under two different licenses: + * - GNU General Public License version 3 (GPLv3) + * - Pimcore Commercial License (PCL) + * Full copyright and license information is available in + * LICENSE.md which is distributed with this source code. + * + * @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) + * @license http://www.pimcore.org/license GPLv3 and PCL */ -declare(strict_types=1); namespace Pimcore\Model\DataObject\ClassDefinition\Data\Extension; From d12cc49199e2eff3f68a967e7d74ac5ffc184389 Mon Sep 17 00:00:00 2001 From: fszenborn Date: Fri, 29 Oct 2021 13:38:44 +0200 Subject: [PATCH 16/16] Gridfilter on relation fields - ignore requestNicePath --- bundles/AdminBundle/Controller/Admin/ElementController.php | 4 ++-- bundles/AdminBundle/Resources/public/js/pimcore/helpers.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bundles/AdminBundle/Controller/Admin/ElementController.php b/bundles/AdminBundle/Controller/Admin/ElementController.php index 217786d6a6a..b795622cc6c 100644 --- a/bundles/AdminBundle/Controller/Admin/ElementController.php +++ b/bundles/AdminBundle/Controller/Admin/ElementController.php @@ -892,7 +892,7 @@ protected function getNicePathFormatterFieldDefinition($source, $context) } /** - * @param Element\AbstractElement $source + * @param DataObject\Concrete $source * @param array $context * @param array $result * @param array $targets @@ -901,7 +901,7 @@ protected function getNicePathFormatterFieldDefinition($source, $context) * * @throws \Exception */ - protected function convertResultWithPathFormatter(Element\AbstractElement $source, $context, $result, $targets): array + protected function convertResultWithPathFormatter(DataObject\Concrete $source, $context, $result, $targets): array { $fd = $this->getNicePathFormatterFieldDefinition($source, $context); diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/helpers.js b/bundles/AdminBundle/Resources/public/js/pimcore/helpers.js index cea7b82b65c..b99e984dd50 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/helpers.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/helpers.js @@ -2538,7 +2538,7 @@ pimcore.helpers.requestNicePathDataGridDecorator = function (gridView, targets) }; pimcore.helpers.requestNicePathData = function (source, targets, config, fieldConfig, context, decorator, responseHandler) { - if (context && context['containerType'] == "batch") { + if (context && (context['containerType'] == "batch" || context['containerType'] == "filterByRelationWindow")) { return; }