You are here

function _inline_entity_form_autocomplete_validate in Inline Entity Form 7

#element_validate callback for the IEF autocomplete field.

1 string reference to '_inline_entity_form_autocomplete_validate'
inline_entity_form_reference_form in ./inline_entity_form.module
Provides the form for adding existing entities through an autocomplete field.

File

./inline_entity_form.module, line 1094
Provides a widget for inline management (creation, modification, removal) of referenced entities. The primary use case is the parent -> children one (for example, order -> line items), where the child entities are never managed outside the…

Code

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

    // Take "label (entity id)', match the id from parenthesis.
    if (preg_match("/.+\\((\\d+)\\)/", $element['#value'], $matches)) {
      $value = $matches[1];
    }
  }
  form_set_value($element, $value, $form_state);
}