function og_group_form in Organic groups 6
Same name and namespace in other branches
- 5.8 og.module \og_group_form()
- 5 og.module \og_group_form()
- 5.2 og.module \og_group_form()
- 5.3 og.module \og_group_form()
- 5.7 og.module \og_group_form()
- 6.2 og.module \og_group_form()
Adds standard fields for any node configured to be a group node.
Parameters
object $node:
2 calls to og_group_form()
- og_form_alter in ./
og.module - og_rules_action_add_group_node_form in includes/
og.rules.inc - Action:Add group node settings to content form.
File
- ./
og.module, line 1331
Code
function og_group_form($node, $form_state) {
global $user;
// Set the default values for a new item. By using += rather than =, we
// only overwrite array keys that have not yet been set. It's safe to use
// on both an empty array, and an incoming array with full or partial data.
$node = (array) $node;
$node += array(
'og_description' => NULL,
'og_theme' => NULL,
'og_language' => NULL,
'nid' => NULL,
);
$node = (object) $node;
$form['og_description'] = array(
'#type' => 'textfield',
'#title' => t('Description'),
'#default_value' => $node->og_description,
'#size' => 70,
'#maxlength' => 150,
'#required' => TRUE,
'#description' => t('A brief description for the group details block and the group directory.'),
'#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'og_description') : -4,
);
$default = isset($node->og_selective) ? $node->og_selective : OG_OPEN;
$options = array(
t('Open - membership requests are accepted immediately.'),
t('Moderated - membership requests must be approved.'),
t('Invite only - membership must be created by an administrator.'),
t('Closed - membership is exclusively managed by an administrator.'),
);
$form['og_selective'] = array(
'#type' => 'radios',
'#title' => t('Membership requests'),
'#required' => TRUE,
'#default_value' => $default,
'#options' => $options,
'#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'og_selective') : 0,
'#description' => t('How should membership requests be handled in this group? When you select <em>closed</em>, users will not be able to join <strong>or</strong> leave.'),
);
// registration checkbox
// get the visibility for normal users
$visibility = variable_get('og_visibility_registration', OG_REGISTRATION_CHOOSE_FALSE);
// admin can always choose registration checkbox - get right default
if (user_access('administer nodes')) {
$visibility = in_array($visibility, array(
OG_REGISTRATION_NEVER,
OG_REGISTRATION_CHOOSE_FALSE,
)) ? OG_REGISTRATION_CHOOSE_FALSE : OG_REGISTRATION_CHOOSE_TRUE;
}
$default = FALSE;
switch ($visibility) {
case OG_REGISTRATION_NEVER:
$form['og_register'] = array(
'#type' => 'value',
'#value' => 0,
);
break;
case OG_REGISTRATION_ALWAYS:
$form['og_register'] = array(
'#type' => 'value',
'#value' => 1,
);
break;
case OG_REGISTRATION_CHOOSE_TRUE:
$default = TRUE;
// fall through
case OG_REGISTRATION_CHOOSE_FALSE:
$form['og_register'] = array(
'#type' => 'checkbox',
'#title' => t('Registration form'),
'#default_value' => isset($node->og_register) ? $node->og_register : $default,
'#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'og_register') : 0,
'#description' => t('May users join this group during registration? If checked, a corresponding checkbox will be added to the registration form.'),
);
break;
}
// directory checkbox
$visibility = variable_get('og_visibility_directory', OG_DIRECTORY_CHOOSE_TRUE);
// override for admins - get right default
if (user_access('administer nodes')) {
$visibility = in_array($visibility, array(
OG_DIRECTORY_NEVER,
OG_DIRECTORY_CHOOSE_FALSE,
)) ? OG_DIRECTORY_CHOOSE_FALSE : OG_DIRECTORY_CHOOSE_TRUE;
}
$default = FALSE;
switch ($visibility) {
case OG_DIRECTORY_NEVER:
$form['og_directory'] = array(
'#type' => 'value',
'#value' => 0,
);
break;
case OG_DIRECTORY_ALWAYS:
$form['og_directory'] = array(
'#type' => 'value',
'#value' => 1,
);
break;
case OG_DIRECTORY_CHOOSE_TRUE:
$default = TRUE;
// fall through
case OG_DIRECTORY_CHOOSE_FALSE:
$form['og_directory'] = array(
'#type' => 'checkbox',
'#title' => t('List in groups directory'),
'#default_value' => isset($node->og_directory) ? $node->og_directory : $default,
'#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'og_directory') : 0,
'#description' => t('Should this group appear on the <a href="@url">list of groups page</a> (requires OG Views module)? Disabled if the group is set to <em>private group</em>.', array(
'@url' => url('og'),
)),
);
break;
}
if (module_exists('locale') && ($languages = locale_language_list())) {
if (count($languages) > 1) {
$form['og_language'] = array(
'#type' => 'radios',
'#title' => t('Group language'),
'#default_value' => $node->og_language,
'#options' => array(
'' => t('Language neutral'),
) + $languages,
'#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'og_language') : 0,
'#description' => t('Selecting a different locale will change the interface language for all group pages and emails. Users who have chosen a preferred language always see their chosen language.'),
);
}
}
if ($theme_form = system_theme_select_form(t('Selecting a different theme will change the look and feel of the group.'), isset($form_state['values']['theme']) ? $form_state['values']['theme'] : $node->og_theme, 2)) {
$theme_form['themes']['#weight'] = 8;
$form += $theme_form;
}
return $form;
}