@@ -649,6 +649,37 @@ new BlogPostCollection(
649
649
);
650
650
```
651
651
652
+ ### Helpers
653
+
654
+ The ` Storyblok\Api\Util\ValueObjectTrait ` provides utility methods for mapping raw Storyblok data arrays into strong PHP
655
+ value objects, enums, and domain models. These helpers reduce boilerplate code and improve readability in DTO
656
+ constructors or factory methods.
657
+
658
+ Use this trait in your value objects or models to simplify the parsing and validation of Storyblok field values.
659
+
660
+ #### Available Methods
661
+
662
+ | Method | Description |
663
+ | -----------------------| ------------------------------------------------------------------------------------------------------------------|
664
+ | ` one() ` | Expects exactly one item (e.g. from a ` blocks ` field). Instantiates one object from it. |
665
+ | ` list() ` | Maps a list of items to objects. Allows setting ` $min ` , ` $max ` , or exact ` $count ` constraints. |
666
+ | ` nullOrOne() ` | Same as ` one() ` , but allows the field to be optional (returns ` null ` if empty). |
667
+ | ` enum() ` | Maps a string value to a backed enum. Supports default value and whitelisting of allowed values. |
668
+ | ` DateTimeImmutable() ` | Returns a ` Safe\DateTimeImmutable ` object from a given date string. |
669
+ | ` Uuid() ` | Returns a ` Storyblok\Api\Domain\Value\Uuid ` instance from a string. |
670
+ | ` Asset() ` | Maps an asset array to a ` Storyblok\Api\Domain\Type\Asset ` object. |
671
+ | ` nullOrAsset() ` | Same as ` Asset() ` , but allows null or invalid input. |
672
+ | ` MultiLink() ` | Maps a multilink array to a ` Storyblok\Api\Domain\Type\MultiLink ` object. |
673
+ | ` nullOrMultiLink() ` | Same as ` MultiLink() ` , but returns ` null ` if ` url ` and ` id ` are missing or empty. |
674
+ | ` RichText() ` | Maps rich text content to a ` Storyblok\Api\Domain\Type\RichText ` object. |
675
+ | ` nullOrRichText() ` | Same as ` RichText() ` , but returns ` null ` if content is empty or only contains whitespace. |
676
+ | ` boolean() ` | Returns ` true ` if the key exists and its value is ` true ` , otherwise ` false ` . |
677
+ | ` zeroOrInteger() ` | Returns an integer from the field, or ` 0 ` if missing. |
678
+ | ` zeroOrFloat() ` | Returns a float from the field, or ` 0.0 ` if missing. |
679
+ | ` string() ` | Returns a trimmed non-empty string (using ` TrimmedNonEmptyString ` ). Optional max length check. |
680
+ | ` nullOrString() ` | Same as ` string() ` , but returns ` null ` if missing or invalid. |
681
+ | ` nullOrEditable() ` | Returns an ` Editable ` instance or ` null ` . |
682
+
652
683
[ actions ] : https://github.com/sensiolabs-de/storyblok-api/actions
653
684
[ codecov ] : https://codecov.io/gh/sensiolabs-de/storyblok-api
654
685
0 commit comments