You are here

function entityreference_dragdrop_element_validate in Entity Reference Drag & Drop 7

Formats the value array properly.

1 string reference to 'entityreference_dragdrop_element_validate'
entityreference_dragdrop_field_widget_form in ./entityreference_dragdrop.module
Implements hook_field_widget_form().

File

./entityreference_dragdrop.module, line 110
Provides a Drag & Drop widget for entity-reference fields.

Code

function entityreference_dragdrop_element_validate($element, &$form_state) {
  $value = array();
  if (!empty($element['#value'])) {
    $ids = explode(',', $element['#value']);
    $value = array();
    foreach ($ids as $id) {
      $value[] = array(
        'target_id' => $id,
      );
    }
  }

  // Update the value of this element so the field can validate the product IDs.
  form_set_value($element, $value, $form_state);
}