diff --git a/core/bootstrap.md b/core/bootstrap.md index d3c87c7441d..640a976f33c 100644 --- a/core/bootstrap.md +++ b/core/bootstrap.md @@ -139,6 +139,7 @@ use Symfony\Component\Serializer\Normalizer\ProblemNormalizer; use Symfony\Component\Serializer\Normalizer\UnwrappingDenormalizer; use Symfony\Component\Serializer\Serializer; +/** @deprecated since API Platform 2.7, will be removed in API Platform 3.0 */ $allowPlainIdentifiers = false; $debug = true; $defaultContext = []; diff --git a/core/configuration.md b/core/configuration.md index a8e1fa45989..2de67004b3b 100644 --- a/core/configuration.md +++ b/core/configuration.md @@ -32,6 +32,7 @@ api_platform: path_segment_name_generator: 'api_platform.path_segment_name_generator.underscore' # Allow using plain IDs for JSON format. + # Deprecated since API Platform 2.7, will be removed in API Platform 3.0 allow_plain_identifiers: false validator: diff --git a/core/serialization.md b/core/serialization.md index 426c4b9d6c2..9d5f3b286a8 100644 --- a/core/serialization.md +++ b/core/serialization.md @@ -408,6 +408,54 @@ class Person ``` +### Plain Identifiers + +Instead of sending an IRI to set a relation, you may want to send a plain identifier. To do so, you must create your own denormalizer: + +```php +iriConverter = $iriConverter; + } + + /** + * {@inheritdoc} + */ + public function denormalize($data, $class, $format = null, array $context = []) + { + $data['relatedDummy'] = $this->iriConverter->getItemIriFromResourceClass(RelatedDummy::class, ['id' => $data['relatedDummy']]); + + return $this->denormalizer->denormalize($data, $class, $format, $context + [__CLASS__ => true]); + } + + /** + * {@inheritdoc} + */ + public function supportsDenormalization($data, $type, $format = null, array $context = []): bool + { + return \in_array($format, ['json', 'jsonld'], true) && is_a($type, Dummy::class, true) && !empty($data['relatedDummy']) && !isset($context[__CLASS__]); + } +} +``` + ## Calculated Field Sometimes you need to expose calculated fields. This can be done by leveraging the groups. This time not on a property, but on a method.