diff --git a/.github/ci/files/config/export.yaml b/.github/ci/files/config/export.yaml index de7bdbb0c4..6d5debb59a 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.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: 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: 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..27f6f25d2f --- /dev/null +++ b/public/js/pimcore/object/gridcolumn/operator/VersionGetter.js @@ -0,0 +1,140 @@ +/** + * 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.versiongetter"); +/** + * @private + */ +pimcore.object.gridcolumn.operator.versiongetter = 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) { + let node; + if (configAttributes) { + 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 + configAttributes = {type: this.type, class: this.class}; + + 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) { + const 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?.callback) { + params.callback(); + } + }, + + allowChild: function (targetNode, dropNode) { + if (targetNode.childNodes.length > 0) { + return false; + } + return true; + } +}); diff --git a/src/DataObject/GridColumnConfig/Operator/VersionGetter.php b/src/DataObject/GridColumnConfig/Operator/VersionGetter.php new file mode 100644 index 0000000000..a39f4a1c77 --- /dev/null +++ b/src/DataObject/GridColumnConfig/Operator/VersionGetter.php @@ -0,0 +1,76 @@ +label = $this->label; + + if(!$element instanceof Concrete){ + // TODO: Should we handle arrays? + return $result; + } + + $children = $this->getChildren(); + + if (!$children) { + return $result; + } + + $c = $children[0]; + + $valueArray = []; + + $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; + } +} 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",