function og_menu_form_alter in Organic Groups Menu (OG Menu) 5
Same name and namespace in other branches
- 8 og_menu.module \og_menu_form_alter()
- 6.2 og_menu.module \og_menu_form_alter()
- 6 og_menu.module \og_menu_form_alter()
- 7.3 og_menu.module \og_menu_form_alter()
- 7.2 og_menu.module \og_menu_form_alter()
File
- ./og_menu.module, line 199
- Modifies the menu module to support menus specific
to organic groups.
Code
function og_menu_form_alter($form_id, &$form) {
if ($form_id == 'menu_edit_item_form' && !user_access('administer all menus')) {
$options = menu_parent_options($item['mid']);
$item_mid = (int) $form['#parameters'][2];
$item_pid = db_result(db_query('SELECT pid FROM {menu} WHERE mid = %d', $item_mid));
if (empty($item_pid)) {
$item_pid = NULL;
}
$og_menu = _generate_menu_listing();
foreach ($og_menu as $og_mid => $array) {
foreach ($options as $mid => $title) {
if ($og_mid == $mid) {
$og_options[$mid] = $title;
}
}
}
$form['pid'] = array(
'#type' => 'select',
'#title' => t('Parent item'),
'#default_value' => $item_pid,
'#options' => $og_options,
);
}
elseif (isset($form['type']) && $form['type']['#value'] . '_node_form' == $form_id) {
$groups = og_menu_generate_group_listing();
if (variable_get('og_audience_required', '') == 1) {
$gid_count = count($groups);
}
else {
$gid_count = NULL;
}
foreach ($groups as $gid => $array) {
$options[$gid] = $array['title'];
}
$node = $form['#node'];
if ($node->nid || $node->og_groups) {
$groups = $node->og_groups[0];
}
else {
if (isset($_GET['gids'])) {
$groups = $_GET['gids'];
}
else {
$groups = array();
}
}
$is_group_type = og_is_group_type($form['type']['#value']);
if (!empty($gid_count) && $gid_count == 1) {
unset($form['og_nodeapi']['visible']['og_groups']);
}
elseif ($is_group_type === TRUE) {
}
else {
$form['og_nodeapi']['visible']['og_groups'] = array(
'#type' => 'select',
'#title' => t('Audience'),
'#attributes' => array(
'class' => 'og-audience',
),
'#options' => $options,
'#description' => format_plural(count($options), 'Show this post in this group.', 'Show this post in these groups.'),
'#default_value' => $groups,
'#multiple' => TRUE,
);
}
if (!user_access('administer all menus')) {
$options = menu_parent_options($item['mid']);
$item_mid = $form['menu']['mid']['#value'];
$item_pid = db_result(db_query('SELECT pid FROM {menu} WHERE mid = %d', $item_mid));
if (empty($item_pid)) {
$item_pid = NULL;
}
$og_menu = _generate_menu_listing();
foreach ($og_menu as $og_mid => $array) {
foreach ($options as $mid => $title) {
if ($og_mid == $mid) {
$og_options[$mid] = $title;
}
}
}
$form['menu']['pid'] = array(
'#type' => 'select',
'#title' => t('Parent item'),
'#default_value' => $item_pid,
'#options' => $og_options,
);
}
if (!user_access('administer nodes')) {
$access = "create " . check_plain($form['type']['#value']) . " content";
$form['options'] = array(
'#type' => 'fieldset',
'#access' => user_access($access),
'#title' => t('Publishing options'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 25,
);
$form['options']['status'] = array(
'#type' => 'checkbox',
'#title' => t('Published'),
'#default_value' => $node->status,
);
$form['options']['promote'] = array(
'#type' => 'checkbox',
'#title' => t('Promoted to front page'),
'#default_value' => $node->promote,
);
$form['options']['sticky'] = array(
'#type' => 'checkbox',
'#title' => t('Sticky at top of lists'),
'#default_value' => $node->sticky,
);
$form['options']['revision'] = array(
'#type' => 'checkbox',
'#title' => t('Create new revision'),
'#default_value' => $node->revision,
);
}
}
}