Skip to content

Commit

Permalink
do not call configureOptions on __set_state
Browse files Browse the repository at this point in the history
  • Loading branch information
jheimbach committed Jan 10, 2025
1 parent 7866852 commit 5b6fc90
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 14 deletions.
45 changes: 36 additions & 9 deletions src/Pimcore/Model/DataObject/ClassDefinition/Data/TargetGroup.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand All @@ -10,8 +11,8 @@
* 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
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Model\DataObject\ClassDefinition\Data;
Expand All @@ -28,8 +29,11 @@ class TargetGroup extends Model\DataObject\ClassDefinition\Data\Select
*
* @see ResourcePersistenceAwareInterface::getDataFromResource
*/
public function getDataFromResource(mixed $data, Dataobject\Concrete $object = null, array $params = []): null|string|int
{
public function getDataFromResource(
mixed $data,
Dataobject\Concrete $object = null,
array $params = []
): null|string|int {
if (!empty($data)) {
try {
$this->checkValidity($data, true, $params);
Expand All @@ -46,8 +50,12 @@ public function getDataFromResource(mixed $data, Dataobject\Concrete $object = n
*
* @see ResourcePersistenceAwareInterface::getDataForResource
*/
public function getDataForResource(mixed $data, DataObject\Concrete $object = null, array $params = []): null|string|int
{
public function getDataForResource(
mixed $data,
DataObject\Concrete $object = null,
array $params = []
): null|string|int {
$this->init();
if (!empty($data)) {
try {
$this->checkValidity($data, true, $params);
Expand Down Expand Up @@ -75,7 +83,7 @@ public function configureOptions(): void
foreach ($targetGroups as $targetGroup) {
$options[] = [
'value' => $targetGroup->getId(),
'key' => $targetGroup->getName(),
'key' => $targetGroup->getName(),
];
}

Expand All @@ -100,8 +108,7 @@ public function checkValidity(mixed $data, bool $omitMandatoryCheck = false, arr
public static function __set_state(array $data): static
{
$obj = parent::__set_state($data);
$options = $obj->getOptions();
if (\Pimcore::inAdmin() || empty($options)) {
if (\Pimcore::inAdmin()) {
$obj->configureOptions();
}

Expand Down Expand Up @@ -129,4 +136,24 @@ public function getFieldType(): string
{
return 'targetGroup';
}

public function __wakeup(): void
{
$this->init();
}

/**
* @return $this
* @internal
*
*/
private function init(): static
{
$options = $this->getOptions();
if (empty($options)) {
$this->configureOptions();
}

return $this;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand All @@ -10,8 +11,8 @@
* 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
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Model\DataObject\ClassDefinition\Data;
Expand All @@ -38,7 +39,7 @@ public function configureOptions(): void
foreach ($targetGroups as $targetGroup) {
$options[] = [
'value' => $targetGroup->getId(),
'key' => $targetGroup->getName(),
'key' => $targetGroup->getName(),
];
}

Expand All @@ -48,8 +49,7 @@ public function configureOptions(): void
public static function __set_state(array $data): static
{
$obj = parent::__set_state($data);
$options = $obj->getOptions();
if (\Pimcore::inAdmin() || empty($options)) {
if (\Pimcore::inAdmin()) {
$obj->configureOptions();
}

Expand Down Expand Up @@ -77,4 +77,24 @@ public function getFieldType(): string
{
return 'targetGroupMultiselect';
}

public function __wakeup(): void
{
$this->init();
}

/**
* @return $this
* @internal
*
*/
private function init(): static
{
$options = $this->getOptions();
if (empty($options)) {
$this->configureOptions();
}

return $this;
}
}

0 comments on commit 5b6fc90

Please sign in to comment.