function _inline_conditions_autocomplete_validate in Inline Conditions 7
Private Callback: Ensure that autocomplete is valid.
Parameters
array $element: Current element array.
array $form_state: The form state array.
array $form: the form array.
File
- ./
inline_conditions.module, line 255 - Extends Drupal 7 with a new field type to manage rules conditions directly from a field.
Code
function _inline_conditions_autocomplete_validate($element, &$form_state, $form) {
$value = array();
// If a value was entered into the autocomplete...
if (!empty($element['#value'])) {
$entities = drupal_explode_tags($element['#value']);
$value = array();
foreach ($entities as $entity) {
// Take "label (entity id)', match the id from parenthesis.
if (preg_match("/.+\\((\\d+)\\)/", $entity, $matches)) {
$value[] = array(
'target_id' => $matches[1],
);
}
}
}
// Update the value of this element with only the entity ids.
form_set_value($element, $value, $form_state);
}