You are here

function uuidreference_autocomplete_validate in UUID reference field 7

Validation callback for autocomplete strings.

Parameters

$element:

$form_state:

$form:

1 string reference to 'uuidreference_autocomplete_validate'
uuidreference_field_widget_form in ./uuidreference.module
Implements hook_field_widget_form().

File

./uuidreference.module, line 277

Code

function uuidreference_autocomplete_validate($element, &$form_state, $form) {
  $value = '';
  if (!empty($element['#value'])) {

    // Match UUID from "label [UUID]".
    if (preg_match("/.+\\[([a-f0-9\\-]+)\\]/", $element['#value'], $matches)) {
      $value = $matches[1];
    }
    else {
      $value = $element['#value'];
    }
  }

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