Building entities in ContentEntityForm::validateForm() can throw exceptions

Created on 17 July 2017, over 7 years ago
Updated 10 September 2024, 2 months ago

Problem/Motivation

Follow up tp 📌 Use modals for creating, updating, and deleting workflows, with a new DialogFormTrait Needs review .

In Workflows module the entity form copyFormValuesToEntity() methods call entity methods such as addTransition() and addState() which throw exceptions for invalid values. However this is performed as part of the buildEntity() method called during validation in ContentEntityForm, causing exceptions to be thrown before validation.

This could also happen to other contrib or custom modules which introduce any code that is executed during the entity being built.

Proposed resolution

@berdir suggested

Only build and validate the entity if there are no form-level validation errors. Then we could have #element_validate and similar things for elements that could break an entity just by setting them. And rest could possibly introduce a pre validate method or something that would allow entities to inspect the raw values before they are set? Or we'd define a special exception interface that rest would be able to handle in a meaningful way.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Closed: outdated

Version

11.0 🔥

Component
Entity  →

Last updated about 4 hours ago

Created by

🇬🇧United Kingdom timmillwood 🏴󠁧󠁢󠁷󠁬󠁳󠁿 Wales, UK

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024