Skip to content

Commit 6f4629b

Browse files
authored
[Data Object Editor] User select data type miss-match (#917)
* add user list adapter * Apply php-cs-fixer changes
1 parent cd5d300 commit 6f4629b

3 files changed

Lines changed: 71 additions & 1 deletion

File tree

config/data_objects.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ services:
177177
Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter\UrlSlugAdapter:
178178
tags: [ 'pimcore.studio_backend.data_adapter' ]
179179

180+
Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter\UserAdapter:
181+
tags: [ 'pimcore.studio_backend.data_adapter' ]
182+
180183
Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter\VideoAdapter:
181184
tags: [ 'pimcore.studio_backend.data_adapter' ]
182185

config/pimcore/config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ pimcore_studio_backend:
160160
- "gender"
161161
- "language"
162162
- "select"
163-
- "user"
164163
Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter\SliderAdapter:
165164
- "slider"
166165
Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter\StringAdapter:
@@ -178,6 +177,8 @@ pimcore_studio_backend:
178177
- "table"
179178
Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter\UrlSlugAdapter:
180179
- "urlSlug"
180+
Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter\UserAdapter:
181+
- "user"
181182
Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter\QuantityValueAdapter:
182183
- "quantityValue"
183184
Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter\InputQuantityValueAdapter:
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* Pimcore
6+
*
7+
* This source file is available under two different licenses:
8+
* - GNU General Public License version 3 (GPLv3)
9+
* - Pimcore Commercial License (PCL)
10+
* Full copyright and license information is available in
11+
* LICENSE.md which is distributed with this source code.
12+
*
13+
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
14+
* @license http://www.pimcore.org/license GPLv3 and PCL
15+
*/
16+
17+
namespace Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Adapter;
18+
19+
use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\DataNormalizerInterface;
20+
use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData;
21+
use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface;
22+
use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface;
23+
use Pimcore\Model\DataObject\ClassDefinition\Data;
24+
use Pimcore\Model\DataObject\ClassDefinition\Data\User;
25+
use Pimcore\Model\DataObject\Concrete;
26+
use Pimcore\Model\UserInterface;
27+
use Pimcore\Normalizer\NormalizerInterface;
28+
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
29+
use function array_key_exists;
30+
use function is_int;
31+
32+
/**
33+
* @internal
34+
*/
35+
#[AutoconfigureTag(DataAdapterLoaderInterface::ADAPTER_TAG)]
36+
final readonly class UserAdapter implements SetterDataInterface, DataNormalizerInterface
37+
{
38+
public function getDataForSetter(
39+
Concrete $element,
40+
Data $fieldDefinition,
41+
string $key,
42+
array $data,
43+
UserInterface $user,
44+
?FieldContextData $contextData = null,
45+
bool $isPatch = false
46+
): ?int {
47+
48+
if (!array_key_exists($key, $data) ||
49+
!$fieldDefinition instanceof NormalizerInterface ||
50+
!is_int($data[$key])
51+
) {
52+
return null;
53+
}
54+
55+
return $data[$key];
56+
}
57+
58+
public function normalize(mixed $value, Data $fieldDefinition): ?int
59+
{
60+
if ($value === null || !$fieldDefinition instanceof User) {
61+
return null;
62+
}
63+
64+
return (int)$value;
65+
}
66+
}

0 commit comments

Comments
 (0)