You are here

function og_vocab_element_validate in OG Vocabulary 7

Validate handler; Re-build the submited values.

TODO: Deal with non-accessible by the user values -- re add them.

1 string reference to 'og_vocab_element_validate'
OgVocab::getFormElement in includes/og_vocab.og_vocab.inc
Return form element.

File

includes/og_vocab.og_vocab.inc, line 305
A class used for messages.

Code

function og_vocab_element_validate($form, &$form_state) {
  $entity_type = $form['#entity_type'];
  $bundle = $form['#bundle'];
  foreach (array_keys(og_vocab_get_og_vocab_fields($entity_type, $bundle)) as $field_name) {
    if (empty($form_state['values'][$field_name][LANGUAGE_NONE][0])) {
      continue;
    }
    $ids = array();
    foreach ($form_state['values'][$field_name][LANGUAGE_NONE][0] as $vid => &$values) {
      if (!is_numeric($vid)) {
        continue;
      }
      foreach ($values as $key => &$value) {
        if (!is_numeric($key)) {

          // "_weight" field.
          continue;
        }
        if (isset($value['target_id']) && empty($value['target_id'])) {

          // Empty field.
          continue;
        }
        $ids[] = $value;
      }
    }
    form_set_value($form[$field_name][LANGUAGE_NONE], $ids, $form_state);
  }
}