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