From c3a6f40f6d14c38ec479ad3ff2546839d022f782 Mon Sep 17 00:00:00 2001 From: Alex Rothberg Date: Tue, 12 Nov 2024 22:18:17 -0500 Subject: [PATCH 01/10] Add Operator for pulling newest version --- .github/ci/files/config/export.yaml | 7 + .../gridcolumn/operator/VersionGetter.js | 139 ++++++++++++++++++ .../Operator/VersionGetter.php | 72 +++++++++ 3 files changed, 218 insertions(+) create mode 100644 public/js/pimcore/object/gridcolumn/operator/VersionGetter.js create mode 100644 src/DataObject/GridColumnConfig/Operator/VersionGetter.php diff --git a/.github/ci/files/config/export.yaml b/.github/ci/files/config/export.yaml index de7bdbb0c4..b58ea09b1f 100644 --- a/.github/ci/files/config/export.yaml +++ b/.github/ci/files/config/export.yaml @@ -248,6 +248,13 @@ services: tags: - { name: pimcore.data_object.grid_column_config.operator_factory, id: Alias } + pimcore.data_object.grid_column_config.operator.factory.versionvaluegetter: + class: Pimcore\Bundle\AdminBundle\DataObject\GridColumnConfig\Operator\Factory\DefaultOperatorFactory + arguments: + $className: Pimcore\Bundle\AdminBundle\DataObject\GridColumnConfig\Operator\VersionGetter + tags: + - { name: pimcore.data_object.grid_column_config.operator_factory, id: VersionGetter } + pimcore.data_object.grid_column_config.operator.factory.workflowstate: class: Pimcore\Bundle\AdminBundle\DataObject\GridColumnConfig\Operator\Factory\WorkflowStateFactory tags: diff --git a/public/js/pimcore/object/gridcolumn/operator/VersionGetter.js b/public/js/pimcore/object/gridcolumn/operator/VersionGetter.js new file mode 100644 index 0000000000..16eb1e5115 --- /dev/null +++ b/public/js/pimcore/object/gridcolumn/operator/VersionGetter.js @@ -0,0 +1,139 @@ +/** + * 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. + * + * @category Pimcore + * @package Object + * + * @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) + * @license http://www.pimcore.org/license GPLv3 and PCL + */ + + +pimcore.registerNS("pimcore.object.gridcolumn.operator.version_getter"); +/** + * @private + */ +pimcore.object.gridcolumn.operator.version_getter = Class.create(pimcore.object.gridcolumn.operator.text, { + type: "operator", + operatorGroup: null, + class: "VersionGetter", + iconCls: "pimcore_icon_operator_alias", + defaultText: "VersionGetter", + group: "other", + + getConfigTreeNode: function (configAttributes) { + if (configAttributes) { + var node = { + draggable: true, + iconCls: this.iconCls, + text: configAttributes.label, + configAttributes: configAttributes, + isTarget: true, + allowChildren: true, + expanded: true, + leaf: false, + expandable: false, + isChildAllowed: this.allowChild + }; + } else { + + //For building up operator list + var configAttributes = {type: this.type, class: this.class}; + + var node = { + draggable: true, + iconCls: this.iconCls, + text: this.getDefaultText(), + configAttributes: configAttributes, + isTarget: true, + leaf: true, + isChildAllowed: this.allowChild + }; + } + node.isOperator = true; + return node; + }, + + + getCopyNode: function (source) { + var copy = source.createNode({ + iconCls: this.iconCls, + text: source.data.text, + isTarget: true, + leaf: false, + expandable: false, + isOperator: true, + configAttributes: { + label: source.data.text, + type: this.type, + class: this.class + + }, + isChildAllowed: this.allowChild + }); + + return copy; + }, + + + getConfigDialog: function (node, params) { + this.node = node; + + this.textfield = new Ext.form.TextField({ + fieldLabel: t('label'), + length: 255, + width: 200, + value: this.node.data.configAttributes.label, + renderer: Ext.util.Format.htmlEncode + }); + + this.configPanel = new Ext.Panel({ + layout: "form", + bodyStyle: "padding: 10px;", + items: [this.textfield], + buttons: [{ + text: t("apply"), + iconCls: "pimcore_icon_apply", + handler: function () { + this.commitData(params); + }.bind(this) + }] + }); + + this.window = new Ext.Window({ + width: 400, + height: 300, + modal: true, + title: t('settings'), + layout: "fit", + items: [this.configPanel] + }); + + this.window.show(); + return this.window; + }, + + commitData: function (params) { + this.node.data.configAttributes.label = this.textfield.getValue(); + this.node.set('text', this.textfield.getValue()); + this.node.set('isOperator', true); + + this.window.close(); + if (params && params.callback) { + params.callback(); + } + }, + + allowChild: function (targetNode, dropNode) { + if (targetNode.childNodes.length > 0) { + return false; + } + return true; + } +}); \ No newline at end of file diff --git a/src/DataObject/GridColumnConfig/Operator/VersionGetter.php b/src/DataObject/GridColumnConfig/Operator/VersionGetter.php new file mode 100644 index 0000000000..8a9b10c1f8 --- /dev/null +++ b/src/DataObject/GridColumnConfig/Operator/VersionGetter.php @@ -0,0 +1,72 @@ +label = $this->label; + + $children = $this->getChildren(); + + if (!$children) { + return $result; + } else { + $c = $children[0]; + + $valueArray = []; + + if($element){ + $latestVersion = $element->getLatestVersion(null, false); + if($latestVersion){ + $element = $latestVersion->loadData(); + } + } + + $childResult = $c->getLabeledValue($element); + $isArrayType = $childResult->isArrayType ?? null; + $childValues = $childResult->value; + if ($childValues && !$isArrayType) { + $childValues = [$childValues]; + } + + if ($childValues) { + /** @var string $childValue */ + foreach ($childValues as $childValue) { + $valueArray[] = $childValue; + } + } + + $result->isArrayType = $isArrayType; + if ($isArrayType) { + $result->value = $valueArray; + } else { + $result->value = $valueArray[0] ?? null; + } + } + + return $result; + } +} From 53986545461cb8128fa016fccb7b81bb9436a924 Mon Sep 17 00:00:00 2001 From: Alex Rothberg Date: Tue, 12 Nov 2024 23:00:55 -0500 Subject: [PATCH 02/10] fix naming --- public/js/pimcore/object/gridcolumn/operator/VersionGetter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/js/pimcore/object/gridcolumn/operator/VersionGetter.js b/public/js/pimcore/object/gridcolumn/operator/VersionGetter.js index 16eb1e5115..e34c16f5f1 100644 --- a/public/js/pimcore/object/gridcolumn/operator/VersionGetter.js +++ b/public/js/pimcore/object/gridcolumn/operator/VersionGetter.js @@ -15,11 +15,11 @@ */ -pimcore.registerNS("pimcore.object.gridcolumn.operator.version_getter"); +pimcore.registerNS("pimcore.object.gridcolumn.operator.versiongetter"); /** * @private */ -pimcore.object.gridcolumn.operator.version_getter = Class.create(pimcore.object.gridcolumn.operator.text, { +pimcore.object.gridcolumn.operator.versiongetter = Class.create(pimcore.object.gridcolumn.operator.text, { type: "operator", operatorGroup: null, class: "VersionGetter", From 60ae0a46fe6769320ea3ba051f6a490414eda94d Mon Sep 17 00:00:00 2001 From: Alex Rothberg Date: Tue, 12 Nov 2024 23:04:00 -0500 Subject: [PATCH 03/10] naming and whitespace --- .github/ci/files/config/export.yaml | 2 +- public/js/pimcore/object/gridcolumn/operator/VersionGetter.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/ci/files/config/export.yaml b/.github/ci/files/config/export.yaml index b58ea09b1f..6d5debb59a 100644 --- a/.github/ci/files/config/export.yaml +++ b/.github/ci/files/config/export.yaml @@ -248,7 +248,7 @@ services: tags: - { name: pimcore.data_object.grid_column_config.operator_factory, id: Alias } - pimcore.data_object.grid_column_config.operator.factory.versionvaluegetter: + pimcore.data_object.grid_column_config.operator.factory.versiongetter: class: Pimcore\Bundle\AdminBundle\DataObject\GridColumnConfig\Operator\Factory\DefaultOperatorFactory arguments: $className: Pimcore\Bundle\AdminBundle\DataObject\GridColumnConfig\Operator\VersionGetter diff --git a/public/js/pimcore/object/gridcolumn/operator/VersionGetter.js b/public/js/pimcore/object/gridcolumn/operator/VersionGetter.js index e34c16f5f1..13d0e7f2b3 100644 --- a/public/js/pimcore/object/gridcolumn/operator/VersionGetter.js +++ b/public/js/pimcore/object/gridcolumn/operator/VersionGetter.js @@ -136,4 +136,4 @@ pimcore.object.gridcolumn.operator.versiongetter = Class.create(pimcore.object.g } return true; } -}); \ No newline at end of file +}); From 2778f612ece3e7654682b9179e3dec2f1f9265b5 Mon Sep 17 00:00:00 2001 From: Alex Rothberg Date: Wed, 13 Nov 2024 12:45:29 -0500 Subject: [PATCH 04/10] fix typing --- src/DataObject/GridColumnConfig/Operator/VersionGetter.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/DataObject/GridColumnConfig/Operator/VersionGetter.php b/src/DataObject/GridColumnConfig/Operator/VersionGetter.php index 8a9b10c1f8..66d4e9c4da 100644 --- a/src/DataObject/GridColumnConfig/Operator/VersionGetter.php +++ b/src/DataObject/GridColumnConfig/Operator/VersionGetter.php @@ -18,6 +18,7 @@ use Pimcore\Bundle\AdminBundle\DataObject\GridColumnConfig\ResultContainer; use Pimcore\Model\Element\ElementInterface; +use Pimcore\Model\DataObject\Concrete; /** * @internal @@ -29,6 +30,11 @@ public function getLabeledValue(array|ElementInterface $element): ResultContaine $result = new \stdClass(); $result->label = $this->label; + if(!$element instanceof Concrete){ + // TODO: Should we handle arrays? + return $result; + } + $children = $this->getChildren(); if (!$children) { From 017034201d96ec6961b87ded2b71537ea5a01665 Mon Sep 17 00:00:00 2001 From: Alex Rothberg Date: Wed, 13 Nov 2024 12:53:43 -0500 Subject: [PATCH 05/10] remove null check --- .../GridColumnConfig/Operator/VersionGetter.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/DataObject/GridColumnConfig/Operator/VersionGetter.php b/src/DataObject/GridColumnConfig/Operator/VersionGetter.php index 66d4e9c4da..6cf41c63b4 100644 --- a/src/DataObject/GridColumnConfig/Operator/VersionGetter.php +++ b/src/DataObject/GridColumnConfig/Operator/VersionGetter.php @@ -44,11 +44,9 @@ public function getLabeledValue(array|ElementInterface $element): ResultContaine $valueArray = []; - if($element){ - $latestVersion = $element->getLatestVersion(null, false); - if($latestVersion){ - $element = $latestVersion->loadData(); - } + $latestVersion = $element->getLatestVersion(null, false); + if($latestVersion){ + $element = $latestVersion->loadData(); } $childResult = $c->getLabeledValue($element); From c2dbc251a9d2599407e839117babc96c9d964715 Mon Sep 17 00:00:00 2001 From: Alex Rothberg Date: Thu, 21 Nov 2024 18:58:23 -0500 Subject: [PATCH 06/10] let/const --- .../object/gridcolumn/operator/VersionGetter.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/public/js/pimcore/object/gridcolumn/operator/VersionGetter.js b/public/js/pimcore/object/gridcolumn/operator/VersionGetter.js index 13d0e7f2b3..d06bd260b5 100644 --- a/public/js/pimcore/object/gridcolumn/operator/VersionGetter.js +++ b/public/js/pimcore/object/gridcolumn/operator/VersionGetter.js @@ -21,15 +21,16 @@ pimcore.registerNS("pimcore.object.gridcolumn.operator.versiongetter"); */ pimcore.object.gridcolumn.operator.versiongetter = Class.create(pimcore.object.gridcolumn.operator.text, { type: "operator", - operatorGroup: null, + operatorGroup: null, class: "VersionGetter", iconCls: "pimcore_icon_operator_alias", defaultText: "VersionGetter", group: "other", - + getConfigTreeNode: function (configAttributes) { + let node; if (configAttributes) { - var node = { + node = { draggable: true, iconCls: this.iconCls, text: configAttributes.label, @@ -44,9 +45,9 @@ pimcore.object.gridcolumn.operator.versiongetter = Class.create(pimcore.object.g } else { //For building up operator list - var configAttributes = {type: this.type, class: this.class}; + configAttributes = {type: this.type, class: this.class}; - var node = { + node = { draggable: true, iconCls: this.iconCls, text: this.getDefaultText(), @@ -62,7 +63,7 @@ pimcore.object.gridcolumn.operator.versiongetter = Class.create(pimcore.object.g getCopyNode: function (source) { - var copy = source.createNode({ + const copy = source.createNode({ iconCls: this.iconCls, text: source.data.text, isTarget: true, From 9084fcf53fe7cc1df63a978f5b5cd7d18d1d5b86 Mon Sep 17 00:00:00 2001 From: Alex Rothberg Date: Mon, 25 Nov 2024 14:06:33 -0500 Subject: [PATCH 07/10] remove unneeded else --- .../Operator/VersionGetter.php | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/DataObject/GridColumnConfig/Operator/VersionGetter.php b/src/DataObject/GridColumnConfig/Operator/VersionGetter.php index 6cf41c63b4..a39f4a1c77 100644 --- a/src/DataObject/GridColumnConfig/Operator/VersionGetter.php +++ b/src/DataObject/GridColumnConfig/Operator/VersionGetter.php @@ -39,38 +39,38 @@ public function getLabeledValue(array|ElementInterface $element): ResultContaine if (!$children) { return $result; - } else { - $c = $children[0]; + } - $valueArray = []; + $c = $children[0]; - $latestVersion = $element->getLatestVersion(null, false); - if($latestVersion){ - $element = $latestVersion->loadData(); - } + $valueArray = []; - $childResult = $c->getLabeledValue($element); - $isArrayType = $childResult->isArrayType ?? null; - $childValues = $childResult->value; - if ($childValues && !$isArrayType) { - $childValues = [$childValues]; - } + $latestVersion = $element->getLatestVersion(null, false); + if($latestVersion){ + $element = $latestVersion->loadData(); + } - if ($childValues) { - /** @var string $childValue */ - foreach ($childValues as $childValue) { - $valueArray[] = $childValue; - } - } + $childResult = $c->getLabeledValue($element); + $isArrayType = $childResult->isArrayType ?? null; + $childValues = $childResult->value; + if ($childValues && !$isArrayType) { + $childValues = [$childValues]; + } - $result->isArrayType = $isArrayType; - if ($isArrayType) { - $result->value = $valueArray; - } else { - $result->value = $valueArray[0] ?? null; + if ($childValues) { + /** @var string $childValue */ + foreach ($childValues as $childValue) { + $valueArray[] = $childValue; } } + $result->isArrayType = $isArrayType; + if ($isArrayType) { + $result->value = $valueArray; + } else { + $result->value = $valueArray[0] ?? null; + } + return $result; } } From ad587b9c14164f9dd31709e8a082f878bbe8a489 Mon Sep 17 00:00:00 2001 From: Alex Rothberg Date: Mon, 2 Dec 2024 11:14:59 -0500 Subject: [PATCH 08/10] Use null coalesce operator Co-authored-by: robertSt7 <104770750+robertSt7@users.noreply.github.com> --- public/js/pimcore/object/gridcolumn/operator/VersionGetter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/js/pimcore/object/gridcolumn/operator/VersionGetter.js b/public/js/pimcore/object/gridcolumn/operator/VersionGetter.js index d06bd260b5..27f6f25d2f 100644 --- a/public/js/pimcore/object/gridcolumn/operator/VersionGetter.js +++ b/public/js/pimcore/object/gridcolumn/operator/VersionGetter.js @@ -126,7 +126,7 @@ pimcore.object.gridcolumn.operator.versiongetter = Class.create(pimcore.object.g this.node.set('isOperator', true); this.window.close(); - if (params && params.callback) { + if (params?.callback) { params.callback(); } }, From 1c411df8c5d5d97467e624c1d3e10ca57b477535 Mon Sep 17 00:00:00 2001 From: Alex Rothberg Date: Mon, 2 Dec 2024 11:17:29 -0500 Subject: [PATCH 09/10] add js to twig. --- templates/admin/index/index.html.twig | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/admin/index/index.html.twig b/templates/admin/index/index.html.twig index 168e40f179..a703875000 100644 --- a/templates/admin/index/index.html.twig +++ b/templates/admin/index/index.html.twig @@ -489,6 +489,7 @@ "pimcore/object/gridcolumn/operator/LFExpander.js", "pimcore/object/gridcolumn/operator/Trimmer.js", "pimcore/object/gridcolumn/operator/Alias.js", + "pimcore/object/gridcolumn/operator/VersionGetter.js", "pimcore/object/gridcolumn/operator/WorkflowState.js", "pimcore/object/gridcolumn/value/DefaultValue.js", "pimcore/object/gridcolumn/operator/GeopointRenderer.js", From e2811ddbed8e5f07a1380e4c4c9e1f9509a6ba5f Mon Sep 17 00:00:00 2001 From: Alex Rothberg Date: Tue, 10 Dec 2024 01:32:02 -0500 Subject: [PATCH 10/10] Update export.yaml --- config/export.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/config/export.yaml b/config/export.yaml index de7bdbb0c4..6d5debb59a 100644 --- a/config/export.yaml +++ b/config/export.yaml @@ -248,6 +248,13 @@ services: tags: - { name: pimcore.data_object.grid_column_config.operator_factory, id: Alias } + pimcore.data_object.grid_column_config.operator.factory.versiongetter: + class: Pimcore\Bundle\AdminBundle\DataObject\GridColumnConfig\Operator\Factory\DefaultOperatorFactory + arguments: + $className: Pimcore\Bundle\AdminBundle\DataObject\GridColumnConfig\Operator\VersionGetter + tags: + - { name: pimcore.data_object.grid_column_config.operator_factory, id: VersionGetter } + pimcore.data_object.grid_column_config.operator.factory.workflowstate: class: Pimcore\Bundle\AdminBundle\DataObject\GridColumnConfig\Operator\Factory\WorkflowStateFactory tags: