|
32 | 32 | /** |
33 | 33 | * Generic item normalizer. |
34 | 34 | * |
| 35 | + * TODO: do not hardcode "id" |
| 36 | + * |
35 | 37 | * @author Kévin Dunglas <[email protected]> |
36 | 38 | */ |
37 | 39 | class ItemNormalizer extends AbstractItemNormalizer |
@@ -68,17 +70,6 @@ public function denormalize(mixed $data, string $class, ?string $format = null, |
68 | 70 | } |
69 | 71 | } |
70 | 72 |
|
71 | | - // See https://github.com/api-platform/core/pull/7270 - id may be an allowed attribute due to being added in the |
72 | | - // overridden getAllowedAttributes below, in order to allow updating a nested item via ID. But in this case it |
73 | | - // may not "really" be an allowed attribute, ie we don't want to actually use it in denormalization. In this |
74 | | - // scenario it will not be present in parent::getAllowedAttributes |
75 | | - if (isset($data['id'], $context['resource_class'])) { |
76 | | - $parentAllowedAttributes = parent::getAllowedAttributes($class, $context, true); |
77 | | - if (\is_array($parentAllowedAttributes) && !\in_array('id', $parentAllowedAttributes, true)) { |
78 | | - unset($data['id']); |
79 | | - } |
80 | | - } |
81 | | - |
82 | 73 | return parent::denormalize($data, $class, $format, $context); |
83 | 74 | } |
84 | 75 |
|
@@ -122,8 +113,9 @@ private function getContextUriVariables(array $data, $operation, array $context) |
122 | 113 | protected function getAllowedAttributes(string|object $classOrObject, array $context, bool $attributesAsString = false): array|bool |
123 | 114 | { |
124 | 115 | $allowedAttributes = parent::getAllowedAttributes($classOrObject, $context, $attributesAsString); |
125 | | - if (\is_array($allowedAttributes) && ($context['api_denormalize'] ?? false)) { |
126 | | - $allowedAttributes = array_merge($allowedAttributes, ['id']); |
| 116 | + // id is a special case handled above it causes issues not allowing it |
| 117 | + if (\is_array($allowedAttributes) && ($context['api_denormalize'] ?? false) && !in_array('id', $allowedAttributes)) { |
| 118 | + $allowedAttributes[] = 'id'; |
127 | 119 | } |
128 | 120 |
|
129 | 121 | return $allowedAttributes; |
|
0 commit comments