Skip to content

Commit 38614c8

Browse files
committed
Make Page::reference nullable to route null through NotBlank validation
Symfony 8.2 improved how null-for-typed-string is handled during deserialization: instead of a raw TypeError message, it now produces a proper validation violation. Rather than rely on Symfony's internal error message (which changed between 8.1 and 8.2), make the reference column nullable at both the PHP and ORM level so null is accepted during deserialization and our explicit NotBlank constraint fires consistently across all Symfony versions. The "incorrect data types" scenario (which tested the raw TypeError text) is replaced by a null-reference example in the existing violations outline, testing against our own "Please enter a reference." message.
1 parent f9a2143 commit 38614c8

2 files changed

Lines changed: 3 additions & 15 deletions

File tree

features/main/page.feature

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,9 @@ Feature: Page resources
102102
| layout | reference | propertyPath | message | uiComponent |
103103
| null | home | layout | Please specify a layout. | myComponent |
104104
| resource[layout] | | reference | Please enter a reference. | myComponent |
105+
| resource[layout] | null | reference | Please enter a reference. | myComponent |
105106
| resource[layout] | home | uiComponent | Please specify a UI component. | |
106107

107-
@loginUser
108-
Scenario Outline: The page resource returns errors on incorrect data types
109-
Given there is a Layout
110-
When I send a "POST" request to "/_/pages" with data:
111-
| layout | reference | isTemplate |
112-
| <layout> | <reference> | false |
113-
Then the response status code should be 422
114-
And the JSON should be valid according to the schema file "error.schema.json"
115-
And the JSON node "description" should be equal to the string '<message>'
116-
Examples:
117-
| layout | reference | message |
118-
| resource[layout] | null | The type of the "reference" attribute must be "string", "NULL" given. |
119-
120108
@loginAdmin
121109
Scenario: I can delete a page
122110
Given there is a Page

src/Entity/Core/Page.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ class Page extends AbstractPage
4545
#[Groups(['Route:manifest:read'])]
4646
public ?Layout $layout;
4747

48-
#[ORM\Column(unique: true)]
48+
#[ORM\Column(unique: true, nullable: true)]
4949
#[Assert\NotBlank(message: 'Please enter a reference.')]
50-
public string $reference;
50+
public ?string $reference = null;
5151

5252
#[ORM\Column(name: 'is_template')]
5353
#[Assert\NotNull(message: 'Please specify if this page is a template or not.')]

0 commit comments

Comments
 (0)