Skip to content

CollectionField issue since 5.0.9 #7627

@Seb33300

Description

@Seb33300

Describe the bug
Since EA 5.0.9, I am facing a really weird issue when using a CollectionField using __toString() of my entity to render the title of each item in the collection.
The same code works as expected in EA 5.0.8.

To Reproduce

yield CollectionField::new('timeSlots')->onlyOnForms()
    ->useEntryCrudForm(TimeSlotCrudController::class)
    ->renderExpanded()
    ->setRequired(true)
;
class TimeSlot
{
    // ...

    public function __toString(): string
    {
        return ucfirst(\IntlDateFormatter::formatObject($this->getStartDate(), 'eeee d à HH\'h\'mm'));
    }

    // ...
}

Error returned:

An exception has been thrown during the rendering of a template ("IntlDateFormatter::formatObject(): Argument #1 ($datetime) must be of type object, null given") in @EasyAdmin/crud/form_theme.html.twig at line 226.

Even if I replace __toString() to use another property of the entity, it's always returning null

Additional context
getStartDate() is NOT returning null it's a datetime and I can properly render the value if I add var_dump(ucfirst(\IntlDateFormatter::formatObject($this->getStartDate(), 'eeee d à HH\'h\'mm'))) just before the return.

I suspect changes in #7600 to be the cause of that issue.
cc @lacatoire

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions