function commons_trusted_contacts_form_add_privacy_toggle in Drupal Commons 7.3
Adds privacy toggle to a node edit/add form.
2 calls to commons_trusted_contacts_form_add_privacy_toggle()
- commons_trusted_contacts_form_commons_bw_partial_node_form_alter in modules/
commons/ commons_trusted_contacts/ commons_trusted_contacts.module - Implements hook_form_FORM_ID_alter().
- commons_trusted_contacts_form_node_form_alter in modules/
commons/ commons_trusted_contacts/ commons_trusted_contacts.module - Implements hook_form_FORM_ID_alter() Adds Privacy selection to full form for node/add or node/edit.
File
- modules/
commons/ commons_trusted_contacts/ commons_trusted_contacts.module, line 1006
Code
function commons_trusted_contacts_form_add_privacy_toggle(&$form, &$form_state) {
$is_group_content = FALSE;
if (!empty($form[OG_AUDIENCE_FIELD][LANGUAGE_NONE][0]['default']['#default_value']) || !empty($form[OG_AUDIENCE_FIELD][LANGUAGE_NONE][0]['admin']['#default_value'])) {
$is_group_content = TRUE;
}
$form['group_audience_type'] = array(
'#type' => 'radios',
'#title' => t('Post to'),
'#title_display' => 'invisible',
'#default_value' => $is_group_content ? 'custom' : 'private',
'#options' => array(
'custom' => t('Post to specific groups'),
'private' => t('Post privately to all trusted contacts'),
),
'#weight' => 70,
'#attributes' => array(
'class' => array(
'hideable-field',
),
),
'#access' => empty($form_state['hide_audience_toggle']),
// Normally Form API states (https://api.drupal.org/api/drupal/includes!common.inc/function/drupal_process_states/7)
// Would be used here, but it does not support loading multiple similar
// forms on the same page. This is why a simple javascript files is needed
// to perform the task of hiding the groups fields.
'#attached' => array(
'js' => array(
drupal_get_path('module', 'commons_trusted_contacts') . '/scripts/commons-trusted-contacts.js',
),
),
);
}