Auto validate fields on $entity->save(), but allow opt-out

Created on 9 September 2013, over 11 years ago
Updated 24 April 2024, 8 months ago

Problem/Motivation

Field validation (Constraints) is triggered automatically, only on form validation. As discussed with @fago and @amateescu via IRC, it makes more sense to always validate the entity upon save(), unless explicitly requested not to

Proposed resolution

* save()'s signature should be changed to public function save($validate = TRUE);
* When an entity is saved via form (i.e. it was already validated), it should be saved without a 2nd validation.

Original report by @Amitaibu

1) Add ER field to node
2) Create node, and notice \Drupal\Core\Entity\EntityFormController::validate calls validations that invoke the Constraints.
3) Try to create the node programmatically, no validation happens.

Feature request
Status

Closed: works as designed

Version

8.0 ⚰️

Component
Entity 

Last updated about 17 hours ago

Created by

🇮🇱Israel amitaibu Israel

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