https://api.drupal.org/api/drupal/modules!field!field.attach.inc/functio...

Apparently this validates programmatic saves. I've not tried it, so I don't know what it'll handle. Would it, for instance, prevent saving of an entityref field with a target ID that doesn't exist?

Comments

joachim’s picture

Title: should we call field_attach_validate() prior to saving entities? » call field_attach_validate() prior to saving entities
Category: Task » Bug report
Priority: Normal » Major
StatusFileSize
new9.59 KB

Having done some investigating -- it turns out this was never having an effect in my project's codebase due to a bug in OG! -- we definitely should be doing this, and it's a bug that we're not.

joachim’s picture

Status: Active » Needs review
wodenx’s picture

I agree with this in principle. I'd actually assumed that this was handled on the entity api level (for the "clean" or "metadata" controllers) - but recently discovered it is not.

I wonder, though, if we can make it possible to disable this check (a protected $validate_fields property on the controller?), as I'm a little concerned about what this might do to my app clients...

joachim’s picture

Yeah, I'd be fine with a property on the controller to act as a bypass flag.

I'd assumed it was just handled when you saved an entity and the fields saved... but no, you can save any old crap into fields if you just use entity_save(), and it's only if the database schema doesn't tolerate it that you get an error.

joachim’s picture

Status: Needs review » Postponed
joachim’s picture

Status: Postponed » Active
neubreed’s picture

I can confirm after applying the patch that validation is now working when posting entities via services_entity.

Although the message that comes back is generic and nondescript:

"Invalid data for entity in the following fields: field_last_name."

So I've installed field_validation module to customise the messages but this doesn't appear to be compatible. It only works if I check "Set errors using field API" But the message still comes back generic.

Would this be a new issue for field_validation or services_entity?