You are here

function og_vocab_form_taxonomy_form_vocabulary_alter in OG Vocabulary 6

Same name and namespace in other branches
  1. 7 og_vocab.module \og_vocab_form_taxonomy_form_vocabulary_alter()

Implementation of hook_form_FORM-ID_alter().

1) Add group id to the vocabulary if it's a group context. 2) Add own submit handler.

See also

og_vocab_form_taxonomy_form_vocabulary_submit().

File

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

Code

function og_vocab_form_taxonomy_form_vocabulary_alter(&$form, &$form_state) {

  // Get the menu item to determine the context.
  $item = menu_get_item();

  // Group vocab add/ edit vocabulary.
  if (strpos($item['path'], 'node/%/og/vocab/') === 0) {
    $form['og'] = array(
      '#type' => 'value',
      '#value' => $item['map'][1]->nid,
    );
    $group = og_get_types('group');
    $omit = og_get_types('omitted');
    $skip = drupal_map_assoc(array_merge($group, $omit));
    if (function_exists('array_diff_key')) {
      $form['content_types']['nodes']['#options'] = array_diff_key($form['content_types']['nodes']['#options'], $skip);
    }
    else {

      // We can't use array_diff_key as it's PHP 5 function.
      foreach ($skip as $type) {
        unset($form['content_types']['nodes']['#options'][$type]);
      }
    }
  }
  else {
    if (user_access('administer groups')) {
      $form['settings']['og_vocab'] = array(
        '#type' => 'fieldset',
        '#title' => t('Organic groups vocabulary'),
        '#description' => t('A vocabulary can be associated with a certain group.'),
        '#collapsible' => TRUE,
      );

      // Check if group is associated with vocabulary.
      $default_value = !empty($form['vid']) ? og_vocab_get_group($form['vid']['#value']) : array();

      // Get all the groups
      $options = og_all_groups_options();
      $form['settings']['og_vocab']['og'] = array(
        '#type' => 'select',
        '#title' => t('Group'),
        '#description' => t('Select the group this vocabulary should be associated with. No association means this vocabulary can be used for <em>all</em> groups.'),
        '#options' => array(
          '0' => t('- None -'),
        ) + $options,
        '#default_value' => $default_value,
        '#disabled' => empty($options) || !user_access('administer organic groups'),
      );

      // Add submit handler.
      $form['#submit'][] = 'og_vocab_form_taxonomy_form_vocabulary_submit';
    }
  }
}