function dynamic_entity_reference_field_widget_form_validate in Dynamic Entity Reference 7
Element validate callback for dynamic entity reference widget.
1 string reference to 'dynamic_entity_reference_field_widget_form_validate'
File
- ./
dynamic_entity_reference.field.inc, line 176 - Contains field hooks.
Code
function dynamic_entity_reference_field_widget_form_validate($element, &$form_state, $form) {
// If a value was entered into the autocomplete.
$value = NULL;
if (!empty($element['#value'])) {
// Take "label (entity id)', match the id from parenthesis.
if (preg_match("/.+\\((\\d+)\\)/", $element['#value'], $matches)) {
$value = $matches[1];
}
elseif (preg_match("/.+\\(([\\w.]+)\\)/", $element['#value'], $matches)) {
$value = $matches[1];
}
}
form_set_value($element, $value, $form_state);
}