I am trying to hide the group_group (request membership) field for organic groups based on a radio button. Here is what I have done that doesn't work:
/**
* Implements hook_form_alter().
*/
function mymodule_form_alter(&$form, &$form_state, $form_id) {
$menu = menu_get_item();
$path = drupal_get_path_alias();
$node = node_load($menu['page_arguments'][0]->nid);
// field_show_group_group is radio button
if($item['field_show_group_group'][LANGUAGE_NONE]['value'] === 0) {
dsm("Just show the subscribe button - NOTHING to do.");
}
else {
dsm("hide button");
$instance = field_info_instance('node', 'group_group', 'community');
$instance['widget']['settings']['og_hide'] = FALSE;
$instance['settings']['behaviors']['og_widget']['access_override'] = FALSE;
unset($instance['widget']['settings']['og_hide']);
unset($instance['settings']['behaviors']['og_widget']['access_override']);
$form['group_group']['#access'] = FALSE;
$form['group_group'][LANGUAGE_NONE][0]['value']['#access'] = FALSE;
unset($form['group_group']);
unset($form['group_group']);
$menu['page_arguments'][0]->group_group['und'][0]['value'] = 0;
unset($menu['page_arguments'][0]);
$item['group_group'][LANGUAGE_NONE][0]['value']['#access'] = FALSE;
unset($item['group_group'][LANGUAGE_NONE][0]['value']['#access']);
$node->group_group[LANGUAGE_NONE][0]['value']['#access'] = FALSE;
}
These are all possibilities I couldn't think of, which of course for some reason don't work. I searched the whole internet for this including drupal.org, drupal.stackexchange, google and stackoverflow. Can you help?
$form['group_group']['#access'] = FALSE;
but as far as I see, this wont work because the$item
is undefined all the time. If this doesn't work I can think only one think, your code doesn't run. Also check if this field appears like 'group_group' in the$form
and not like 'field_group_group' or similar strange way.$form['group_group']['#access'] = FALSE;
to hide the field, maybe you need to check this patch drupal.org/project/og/issues/2278003 if you testing like an anonymous user.$form['group_group']['#access'] = FALSE;
you need to use this, from the form alter. It's works in my system, if in yours doesn't, that means something overwrite this in your system.