function og_vocab_form_alter in OG Vocabulary 5
Same name and namespace in other branches
- 6 og_vocab.module \og_vocab_form_alter()
- 7 og_vocab.module \og_vocab_form_alter()
Implementation of hook_form_alter().
File
- ./
og_vocab.module, line 188 - Give each group its own system controlled vocabularies
Code
function og_vocab_form_alter($form_id, &$form) {
switch ($form_id) {
case 'taxonomy_form_vocabulary':
if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'og') {
$form['module'] = array(
'#type' => 'value',
'#value' => 'og_vocab',
);
$form['og'] = array(
'#type' => 'value',
'#value' => arg(1),
);
$omit = array_merge(variable_get('og_node_types', array(
'og',
)), variable_get('og_omitted', array()));
foreach ($omit as $type) {
unset($form['nodes']['#options'][$type]);
}
}
break;
case 'taxonomy_form_term':
$vocab = taxonomy_get_vocabulary($form['vid']['#value']);
if ($vocab->module == 'og_vocab') {
unset($form['synonyms']);
}
break;
case isset($form['type']) && $form['type']['#value'] . '_node_form' == $form_id:
if (isset($form['taxonomy'])) {
// remove from node form those vocabs that belong to groups other than us (if we even have a group)
$groupnode = og_get_group_context();
$where = "(v.module = 'og_vocab' AND ov.nid != %d)";
$sql = "SELECT v.vid, v.tags FROM {vocabulary} v LEFT JOIN {og_vocab} ov ON v.vid = ov.vid WHERE {$where}";
$result = db_query($sql, $groupnode->nid);
while ($row = db_fetch_object($result)) {
if ($row->tags) {
unset($form['taxonomy']['tags'][$row->vid]);
}
else {
unset($form['taxonomy'][$row->vid]);
}
}
// remove categories fieldset if no vocabularies remain
// first, unset tags if needed
if (!count($form['taxonomy']['tags'])) {
unset($form['taxonomy']['tags']);
}
if (!count(element_children($form['taxonomy']))) {
unset($form['taxonomy']);
}
// If there's only one element remove the fieldset but keep the children
if (count(element_children($form['taxonomy'])) == 1) {
unset($form['taxonomy']['#type']);
unset($form['taxonomy']['#title']);
unset($form['taxonomy']['#collapsible']);
unset($form['taxonomy']['#collapsed']);
}
}
break;
}
}