You are here

function og_ui_form_node_type_form_alter in Organic groups 7.2

Same name and namespace in other branches
  1. 7 og_ui/og_ui.module \og_ui_form_node_type_form_alter()

Implement hook_form_FORM_ID_alter().

File

og_ui/og_ui.module, line 883
Organic groups UI.

Code

function og_ui_form_node_type_form_alter(&$form, &$form_state) {
  $node_type = $form['#node_type']->type;
  $form['og'] = array(
    '#type' => 'fieldset',
    '#title' => t('Organic groups'),
    '#collapsible' => TRUE,
    '#group' => 'additional_settings',
    '#description' => t('Specify how OG should treat content of this type. Content may behave as a group, as group content, or may not participate in OG at all.'),
  );

  // Group settings.
  $url = array(
    '!url' => l(t('Manage fields'), '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 .= '<br/>' . t('To unset the group definition you should delete the "Group type" field via !url.', $url);
  }
  $form['og']['og_group_type'] = array(
    '#type' => 'checkbox',
    '#title' => t('Group'),
    '#default_value' => $is_group,
    '#description' => $description,
    '#disabled' => $is_group,
  );

  // Group content settings.
  $is_group_content = og_is_group_content_type('node', $node_type);
  $description = t('Set the content type to be a group content, that can be associated with groups.');
  if ($is_group_content) {
    $description .= '<br/>' . t('To unset the group content definition or change the settings you should delete the "Groups audience" field via !url.', $url);
  }
  $group_content_options = og_get_all_group_entity();
  if (!$group_content_options) {
    $description .= '<br/>' . t('There are no group bundles defined.');
  }
  $form['og']['og_group_content_type'] = array(
    '#type' => 'checkbox',
    '#title' => t('Group content'),
    '#default_value' => $is_group_content,
    '#description' => $description,
    '#disabled' => !$group_content_options || $is_group_content,
  );
  if ($group_content_options) {

    // Don't show the settings, as there might be multiple OG audience fields
    // in the same bundle.
    $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.'),
      '#ajax' => array(
        'callback' => 'og_node_type_form_settings',
        'wrapper' => 'og-settings-wrapper',
      ),
      '#states' => array(
        'visible' => array(
          ':input[name="og_group_content_type"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $target_type = !empty($form_state['values']['target_type']) ? $form_state['values']['target_type'] : key($group_content_options);
    $entity_info = entity_get_info($target_type);
    $bundles = array();
    foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
      if (og_is_group_type($target_type, $bundle_name)) {
        $bundles[$bundle_name] = $bundle_info['label'];
      }
    }

    // Get the bundles that are acting as group.
    $form['og']['target_bundles'] = array(
      '#prefix' => '<div id="og-settings-wrapper">',
      '#suffix' => '</div>',
      '#type' => 'select',
      '#title' => t('Target bundles'),
      '#options' => $bundles,
      '#default_value' => array(),
      '#size' => 6,
      '#multiple' => TRUE,
      '#description' => t('The bundles of the entity type that can be referenced. Optional, leave empty for all bundles.'),
      '#states' => array(
        'visible' => array(
          ':input[name="og_group_content_type"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
  }
}