Thought this might be the same bug as #1941812: Inline entity form doesn't enter in validation function with Conditional Field but I just checked and conditional_fields doesn't use hook_node_validate() to do its thing, so this is a separate bug.

NodeInlineEntityFormController overrides entityFormSubmit() to invoke node_submit() and friends, but it doesn't do the same for node_validate(). This breaks modules like unique_field and is generally an extremely dangerous thing to do. Sites might bake all sorts of validation into their nodes, and if that can be totally bypassed via IEF, badness ensues. ;)

Members fund testing for the Drupal project. Drupal Association Learn more


dww’s picture

Status: Active » Needs work
1.09 KB

Ugh, this is a can of worms. :( I tried the attached patch, and now at least hook_node_validate() is geting invoked. However, when you call form_set_error() from an implementation of that hook, nothing really happens and the form submits, anyway...

But, this is at least a start.

bojanz’s picture

Would it be enough to do:

$form_errors = &drupal_static('form_set_error', array());
if (!empty($form_errors)) {
  $form_state['rebuild'] = TRUE;

After the call to node_validate()?

vasike’s picture

Status: Needs work » Active

it couldn't see a way for a solution. maybe the reverse way could be a solution.
in the given case - IEF integration as feature request for Unique field.
Maybe Field validation module could an alternative solution - i didn't test to see if it works?

bojanz : should this kind ("impossible look like") of issues should be on project page or documentation as known issues?

archnode’s picture

I can confirm that the Field validation module indeed works with IEF if you specify the "Set errors using field API " option.

bojanz’s picture

Issue summary: View changes
Status: Active » Needs work

This is doable, the code needs to catch the newly set form errors and set them on the correct form elements (the ones with the correct parents).

phayes’s picture

Status: Needs work » Needs review
2.37 KB

Attached is a patch that fixes this issue.

The situation is complicated by the fact that node_validate thinks it's validating the entire form, where in reality it's only validating a single element, so we need to do a little bit of manual intervention on the static form error and validation-limits, but it seems to work well.

Please review.

phayes’s picture

Minor error in the above patch. This one should be good.

phayes’s picture

phayes’s picture

Sorry. I found another error. Final patch attached. Please test!

bojanz’s picture

Status: Needs review » Closed (won't fix)

Killing global errors is bound to interfere with other parts of the form.

The node api is broken here, and we'll have to accept that. The few modules that use hook_node_validate() can implement a workaround for IEF.

akolahi’s picture

@bojanz I'm in this position. What's the workaround for IEF?