You are here

function synonyms_select_validate in Synonyms 7

Element validate handler.

Convert selected synonyms into their terms and save the updated data in the value of the form element.

4 string references to 'synonyms_select_validate'
synonyms_commerce_field_widget_form in synonyms_commerce/synonyms_commerce.module
Implements hook_field_widget_form().
synonyms_field_widget_form in ./synonyms.module
Implements hook_field_widget_form().
synonyms_views_handler_filter_entityreference_synonyms::value_form in views/synonyms_views_handler_filter_entityreference_synonyms.inc
Provide a simple textfield for equality
synonyms_views_handler_filter_term_tid::value_form in views/synonyms_views_handler_filter_term_tid.inc
Options form subform for setting options.

File

./synonyms.module, line 1204
Provide synonyms feature for Drupal entities.

Code

function synonyms_select_validate($element, &$form_state) {
  $value = array();
  if ($element['#multiple']) {
    $value = $element['#value'];
  }
  else {
    $value[] = $element['#value'];
  }
  foreach ($value as $k => $v) {

    // For the cases when a synonym was selected and not an entity option, we
    // process the selected values stripping everything that goes after
    // semicolon.
    if (!is_numeric($v)) {
      $entity_id = explode(':', $v);
      $value[$k] = $entity_id[0];
    }
  }

  // The user also might have selected multiple times the same entity, given
  // that an entity can be represented by more than 1 option (an entity and its
  // synonym), then it's possible in theory, so we should be ready for this
  // scenario.
  $value = array_unique($value);
  form_set_value($element, $value, $form_state);
}