Currently a generic message is printed when a relation fails to be saved due to field validation of one or more fields throwing a FieldValidationException.

It'd be helpful if the set of errors returned from field validation were printed so the user has a better idea of why the field validation failed.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

caxy4 created an issue. See original summary.

caxy4’s picture

Attaching a patch that prints all fields that failed validation as an array.

I wasn't sure whether all fields would fit the format I encountered in my test cases, which was:

$e =  array('field_name' => array(
  LANGUAGE_NONE => array(
    0 => array(
      0 => array(
        'error' => 'error_message',
        'message' => 'error_message',
      )
    )
  )
));

...so I chose to print the entire $e->errors array.

Although it's ugly, it gets the information in the watchdog message that'll help the user resolve their field validation error.

This patch builds on https://www.drupal.org/node/1362304 which was the initial implementation of logging a watchdog error when field validation fails.

mikran’s picture

I think there is some structure to the format of errors array. I found this from relation entity collector module:

function _relation_entity_collector_endpoints_validate($relation, $form, &$form_state) {
  // Perform field_level validation.
  try {
    field_attach_validate('relation', $relation);
  }
  catch (FieldValidationException $e) {
    $index = 0;
    // We do not look anything like a field widget so just pile the errors on
    // nonexistent form elements.
    foreach ($e->errors as $field_name => $field_errors) {
      foreach ($field_errors as $langcode => $multiple_errors) {
        foreach ($multiple_errors as $delta => $item_errors) {
          foreach ($item_errors as $item_error) {
            form_set_error('error' . $index++, $item_error['message']);
          }
        }
      }
    }
  }
}

so I think we can use the same iteration structure and set multiple log messages similarly what relation entity collector here is doing.

Attached patch does just that.

mikran’s picture

Status: Needs review » Fixed

committed

  • mikran committed fe8eba2 on 7.x-1.x
    Issue #2546418 by caxy4, mikran: Improve relation_save()'s watchdog...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.