You are here

function og_vocab_field_widget_form in OG Vocabulary 7

Implements hook_field_widget_form().

File

./og_vocab.module, line 439
Give each group its own system controlled vocabularies.

Code

function og_vocab_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  $entity_type = $instance['entity_type'];
  $entity = isset($element['#entity']) ? $element['#entity'] : NULL;
  $field_name = $field['field_name'];
  if (!$entity) {
    return;
  }

  // Cache the processed entity, to make sure we call the widget only once.
  $cache =& drupal_static(__FUNCTION__, array());
  list($id, , $bundle) = entity_extract_ids($entity_type, $entity);
  $identifier = $entity_type . ':' . $id . ':' . $field_name;
  if (isset($cache[$identifier])) {
    return array();
  }
  $cache[$identifier] = TRUE;
  if (!($vids = og_vocab_get_accessible_vocabs($entity_type, $bundle, $field_name))) {
    return;
  }

  // Iterate over vocabularies and build each one.
  foreach ($vids as $vid) {
    $og_vocab = og_vocab_load_og_vocab($vid, $entity_type, $bundle);
    $element[$vid] = $og_vocab
      ->getFormElement($entity_type, $entity, $form, $form_state);
  }
  return $element;
}