Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix - show filtered inherited cs values on grid #604

Open
wants to merge 13 commits into
base: 1.7
Choose a base branch
from
Open
7 changes: 7 additions & 0 deletions .github/ci/files/config/export.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/sync-changes-scheduled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ jobs:
ref:
[
{ "base": "1.x", "destination": "1.x" },
{ "base": "1.7", "destination": "1.7" },
{ "base": "1.6", "destination": "1.6" },
{ "base": "1.7", "destination": "1.7_LTS" },
]
with:
base_ref: ${{ matrix.ref.base }}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
"extra": {
"branch-alias": {
"1.x-dev": "1.7.x-dev"
"1.x-dev": "1.8.x-dev"
},
"pimcore": {
"bundles": [
Expand Down
7 changes: 7 additions & 0 deletions config/export.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
140 changes: 140 additions & 0 deletions public/js/pimcore/object/gridcolumn/operator/VersionGetter.js
Original file line number Diff line number Diff line change
@@ -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;
}
});
76 changes: 76 additions & 0 deletions src/DataObject/GridColumnConfig/Operator/VersionGetter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
declare(strict_types=1);

/**
* 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
*/

namespace Pimcore\Bundle\AdminBundle\DataObject\GridColumnConfig\Operator;

use Pimcore\Bundle\AdminBundle\DataObject\GridColumnConfig\ResultContainer;
use Pimcore\Model\DataObject\Concrete;
use Pimcore\Model\Element\ElementInterface;

/**
* @internal
*/
final class VersionGetter extends AbstractOperator
{
public function getLabeledValue(array|ElementInterface $element): ResultContainer|\stdClass|null
{
$result = new \stdClass();
$result->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;
}
}
1 change: 1 addition & 0 deletions templates/admin/index/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading