diff --git a/og_ui/og_ui.module b/og_ui/og_ui.module
index 7c452288..979ffe65 100644
--- a/og_ui/og_ui.module
+++ b/og_ui/og_ui.module
@@ -914,15 +914,14 @@ function og_ui_form_node_type_form_alter(&$form, &$form_state) {
);
// Group settings.
- $url = array('!url' => l(t('Manage fields'), 'admin/structure/types/manage/' . str_replace('_', '-', $node_type) . '/fields'));
+ $url = '/admin/structure/types/manage/' . str_replace('_', '-', $node_type) . '/fields';
$is_group = og_is_group_type('node', $node_type);
$description = t('Set the content type to be a group, that content will be associated with, and will have group members.');
if ($is_group) {
- $description .= '
' . t('To unset the group definition you should delete the "Group type" field via !url.', $url);
+ $description .= '
' . t('To unset the group definition you should delete the "Group type" field via Manage fields.', array('!url' => $url));
}
-
$form['og']['og_group_type'] = array(
'#type' => 'checkbox',
'#title' => t('Group'),
@@ -936,7 +935,9 @@ function og_ui_form_node_type_form_alter(&$form, &$form_state) {
$description = t('Set the content type to be a group content, that can be associated with groups.');
if ($is_group_content) {
- $description .= '
' . t('To unset the group content definition or change the settings you should delete the "Groups audience" field via !url.', $url);
+ $description .= '
' . t('To unset the group content definition or change the settings you should delete the "Groups audience" field via Manage fields.', array('!url' => $url));
+ } else {
+ $description .= '
' . t('Checking this box will add a default "Group audience" field to this content type.');
}
$group_content_options = og_get_all_group_entity();
if (!$group_content_options) {
@@ -952,14 +953,23 @@ function og_ui_form_node_type_form_alter(&$form, &$form_state) {
);
if ($group_content_options) {
- // Don't show the settings, as there might be multiple OG audience fields
- // in the same bundle.
+ $target_type_default_value = key($group_content_options);
+ $description = t('The entity type that can be referenced thru this field.');
+
+ // Check if this the audience field has already been set up. If so, set the
+ // form default value and disable this select box.
+ $audience_field_info = field_info_field(OG_AUDIENCE_FIELD);
+ if ($audience_field_info) {
+ $target_type_default_value = $audience_field_info['settings']['target_type'];
+ $description .= '
' . t('The target type has already been set for the default "Group audience" field. To change it, edit the "Groups audience" field via Manage fields, or add a new "Group audience" field in OG field settings.', array('!url' => $url, '!url_settings' => '/admin/config/group/fields'));
+ }
+
$form['og']['target_type'] = array(
'#type' => 'select',
'#title' => t('Target type'),
'#options' => $group_content_options,
- '#default_value' => key($group_content_options),
- '#description' => t('The entity type that can be referenced thru this field.'),
+ '#default_value' => $target_type_default_value,
+ '#description' => $description,
'#ajax' => array(
'callback' => 'og_node_type_form_settings',
'wrapper' => 'og-settings-wrapper',
@@ -969,6 +979,11 @@ function og_ui_form_node_type_form_alter(&$form, &$form_state) {
':input[name="og_group_content_type"]' => array('checked' => TRUE),
),
),
+
+ // If the default group audience field has already been set up there is
+ // no point in allowing the user access to this select box. The value
+ // can't be changed from here anyway.
+ '#disabled' => !empty($audience_field_info),
);
$target_type = !empty($form_state['values']['target_type']) ? $form_state['values']['target_type'] : key($group_content_options);
@@ -980,6 +995,13 @@ function og_ui_form_node_type_form_alter(&$form, &$form_state) {
}
}
+ $default_value = array();
+ if ($audience_field_info) {
+ if (!empty($audience_field_info['settings']['handler_settings']['target_bundles'])) {
+ $default_value = $audience_field_info['settings']['handler_settings']['target_bundles'];
+ }
+ };
+
// Get the bundles that are acting as group.
$form['og']['target_bundles'] = array(
'#prefix' => '