Skip to content

Commit

Permalink
fix output channels to work properly with classification stores (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
aweichler authored Apr 19, 2024
1 parent a50eeca commit 62e4742
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 16 deletions.
7 changes: 5 additions & 2 deletions doc/classificationstore.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ different display modes for classification store keys in the output definition c
for eq.
```php
$outputDataConfig = OutputDataConfigToolkitBundle\Service::getOutputDataConfig($object, 'Output config channel');
$outputDataConfig[0]->classificationstore = 'Attributes'; ### classificationstore field name in object
$outputDataConfig[0]->classificationstore_group = 'Product'; ### Classificationstore group name
$outputDataConfig[0]->setClassificationstore('Attributes'); ### classificationstore field name in object
$outputDataConfig[0]->setClassificationstoreGroup('Product'); ### Classificationstore group name
# the old way was access the values directly
// $outputDataConfig[0]->classificationstore = 'Attributes'; ### classificationstore field name in object
// $outputDataConfig[0]->classificationstore_group = 'Product'; ### Classificationstore group name
$outputDataConfig[0]->getLabeledValue($object);
```
26 changes: 26 additions & 0 deletions src/ConfigElement/AbstractConfigElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ abstract class AbstractConfigElement implements IConfigElement

protected $context;

/** @var string|null */
public ?string $classificationstore = null;

/** @var string|null */
public ?string $classificationstore_group = null;

public function __construct($config, $context = null)
{
$this->attribute = $config->attribute ?? null;
Expand All @@ -35,6 +41,26 @@ public function getLabel()
return $this->label;
}

public function getClassificationstore(): ?string
{
return $this->classificationstore;
}

public function getClassificationstoreGroup(): ?string
{
return $this->classificationstore_group;
}

public function setClassificationstore(?string $classificationstore): void
{
$this->classificationstore = $classificationstore;
}

public function setClassificationstoreGroup(?string $classificationstore_group): void
{
$this->classificationstore_group = $classificationstore_group;
}

public function getAttribute()
{
return $this->attribute;
Expand Down
7 changes: 7 additions & 0 deletions src/ConfigElement/Operator/Concatenator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

namespace OutputDataConfigToolkitBundle\ConfigElement\Operator;

use OutputDataConfigToolkitBundle\ConfigElement\AbstractConfigElement;

class Concatenator extends AbstractOperator
{
protected $glue;
Expand Down Expand Up @@ -44,6 +46,11 @@ public function getLabeledValue($object)
$valueArray = [];

foreach ($childs as $c) {
if ($c instanceof AbstractConfigElement) {
$c->setClassificationstore($this->getClassificationstore());
$c->setClassificationstoreGroup($this->getClassificationstoreGroup());
}

$value = $c->getLabeledValue($object) ? $c->getLabeledValue($object)->value : null;

if (!$hasValue) {
Expand Down
6 changes: 6 additions & 0 deletions src/ConfigElement/Operator/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

namespace OutputDataConfigToolkitBundle\ConfigElement\Operator;

use OutputDataConfigToolkitBundle\ConfigElement\AbstractConfigElement;

class Group extends AbstractOperator
{
public function getLabeledValue($object)
Expand All @@ -23,6 +25,10 @@ public function getLabeledValue($object)

$childs = $this->getChilds();
foreach ($childs as $c) {
if ($c instanceof AbstractConfigElement) {
$c->setClassificationstore($this->getClassificationstore());
$c->setClassificationstoreGroup($this->getClassificationstoreGroup());
}
$value = $c->getLabeledValue($object);
if (!empty($value) && !$value->empty && (!method_exists($value, 'isEmpty') || !$value->isEmpty())) {
$valueArray[] = $value;
Expand Down
6 changes: 6 additions & 0 deletions src/ConfigElement/Operator/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

namespace OutputDataConfigToolkitBundle\ConfigElement\Operator;

use OutputDataConfigToolkitBundle\ConfigElement\AbstractConfigElement;

class Table extends AbstractOperator
{
protected $tooltip;
Expand All @@ -37,6 +39,10 @@ public function getLabeledValue($object)
$isEmpty = false;
$valueArray = [];
foreach ($childs as $c) {
if ($c instanceof AbstractConfigElement) {
$c->setClassificationstore($this->getClassificationstore());
$c->setClassificationstoreGroup($this->getClassificationstoreGroup());
}
$row = $c->getLabeledValue($object);
$valueArray[] = $row;
$isEmpty = $row->empty;
Expand Down
9 changes: 8 additions & 1 deletion src/ConfigElement/Operator/TableCol.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

namespace OutputDataConfigToolkitBundle\ConfigElement\Operator;

use OutputDataConfigToolkitBundle\ConfigElement\AbstractConfigElement;

class TableCol extends AbstractOperator
{
protected $colspan;
Expand All @@ -34,7 +36,12 @@ public function getLabeledValue($object)

$childs = $this->getChilds();
if ($childs) {
$value = $childs[0]->getLabeledValue($object);
$c = $childs[0];
if ($c instanceof AbstractConfigElement) {
$c->setClassificationstore($this->getClassificationstore());
$c->setClassificationstoreGroup($this->getClassificationstoreGroup());
}
$value = $c->getLabeledValue($object);
$value->colSpan = $this->colspan;
$value->headline = $this->headline;

Expand Down
6 changes: 6 additions & 0 deletions src/ConfigElement/Operator/TableRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

namespace OutputDataConfigToolkitBundle\ConfigElement\Operator;

use OutputDataConfigToolkitBundle\ConfigElement\AbstractConfigElement;

class TableRow extends AbstractOperator
{
protected $headline;
Expand All @@ -35,6 +37,10 @@ public function getLabeledValue($object)
$valueArray = [];

foreach ($childs as $c) {
if ($c instanceof AbstractConfigElement) {
$c->setClassificationstore($this->getClassificationstore());
$c->setClassificationstoreGroup($this->getClassificationstoreGroup());
}
$col = $c->getLabeledValue($object);
if (!empty($col) && (!$col->empty && !($c instanceof \OutputDataConfigToolkitBundle\ConfigElement\Operator\Text))) {
$isEmpty = false;
Expand Down
9 changes: 8 additions & 1 deletion src/ConfigElement/Operator/TextAddon.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

namespace OutputDataConfigToolkitBundle\ConfigElement\Operator;

use OutputDataConfigToolkitBundle\ConfigElement\AbstractConfigElement;

class TextAddon extends AbstractOperator
{
private $addon;
Expand All @@ -30,7 +32,12 @@ public function getLabeledValue($object)
{
$childs = $this->getChilds();
if (!empty($childs)) {
$value = $childs[0]->getLabeledValue($object);
$c = $childs[0];
if ($c instanceof AbstractConfigElement) {
$c->setClassificationstore($this->getClassificationstore());
$c->setClassificationstoreGroup($this->getClassificationstoreGroup());
}
$value = $c->getLabeledValue($object);

if (!is_null($value->value)) {
$value->value = $value->value.$this->getAddon();
Expand Down
10 changes: 8 additions & 2 deletions src/ConfigElement/Operator/TranslateValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

namespace OutputDataConfigToolkitBundle\ConfigElement\Operator;

use OutputDataConfigToolkitBundle\ConfigElement\AbstractConfigElement;

class TranslateValue extends AbstractOperator
{
private $prefix;
Expand All @@ -31,8 +33,12 @@ public function getLabeledValue($object)
$childs = $this->getChilds();
if ($childs) {
$translator = \Pimcore::getContainer()->get('translator');

$value = $childs[0]->getLabeledValue($object);
$c = $childs[0];
if ($c instanceof AbstractConfigElement) {
$c->setClassificationstore($this->getClassificationstore());
$c->setClassificationstoreGroup($this->getClassificationstoreGroup());
}
$value = $c->getLabeledValue($object);
if ($value->value) {
$value->value = $translator->trans($this->prefix . $value->value);
}
Expand Down
14 changes: 4 additions & 10 deletions src/ConfigElement/Value/DefaultValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ class DefaultValue extends AbstractConfigElement
/** @var string|null */
protected $icon;

/** @var string|null */
public $classificationstore;

/** @var string|null */
public $classificationstore_group;

public function __construct($config, $context = null)
{
parent::__construct($config, $context);
Expand Down Expand Up @@ -157,15 +151,15 @@ public function getLabeledValue($object)
protected function getLabeledValueForClassificationStore($object): ?object
{
// checking classification store fieldname
if (!$this->classificationstore) {
if (!$this->getClassificationstore()) {
return null;
}
$getter = 'get' . ucfirst($this->classificationstore);
$getter = 'get' . ucfirst($this->getClassificationstore());
// checking classification sote group
if (!$this->classificationstore_group) {
if (!$this->getClassificationstoreGroup()) {
return null;
}
$groupDef = Classificationstore\GroupConfig::getByName($this->classificationstore_group);
$groupDef = Classificationstore\GroupConfig::getByName($this->getClassificationstoreGroup());

// classification store
$attribute = str_replace('#cs#', '', $this->attribute);
Expand Down

0 comments on commit 62e4742

Please sign in to comment.