You are here

function og_form_alter in Organic groups 5.8

Same name and namespace in other branches
  1. 5 og.module \og_form_alter()
  2. 5.2 og.module \og_form_alter()
  3. 5.3 og.module \og_form_alter()
  4. 5.7 og.module \og_form_alter()
  5. 6.2 og.module \og_form_alter()
  6. 6 og.module \og_form_alter()
  7. 7 og.module \og_form_alter()

File

./og.module, line 1468

Code

function og_form_alter($form_id, &$form) {

  // Add audience selection to node forms
  if (isset($form['#node']) && $form_id == $form['#node']->type . '_node_form') {
    $node = $form['#node'];
    if (og_is_group_type($node->type)) {
      $form = array_merge($form, og_group_form($node));

      // Don't trample on custom label.
      if ($form['body_filter']['body']['#title'] == t('Body')) {
        $form['body_filter']['body']['#title'] = t('Mission statement');
        $form['body_filter']['body']['#description'] = t('A welcome greeting for your group home page. Consider listing the group objectives and mission.');
      }
      $form['author']['name']['#title'] = t('Group manager');
      $form['options']['sticky']['#title'] = t('Sticky at top of group home page and other lists');
    }
    elseif (og_is_group_post_type($node->type)) {
      if (!$node->nid) {
        if ($group_node = og_get_group_context()) {
          $bc[] = array(
            'path' => 'og',
            'title' => t('Groups'),
          );
          $bc[] = array(
            'path' => "node/{$group_node->nid}",
            'title' => $group_node->title,
          );
          $bc[] = array(
            'path' => "node/add/{$node->type}",
            'title' => t('Create foo'),
          );

          //TODO fix title

          // TODO: not working for unknown reason
          // menu_set_location($bc);
        }
      }
      og_form_add_og_audience($form_id, $form);
    }
  }

  // add option to migrate messages before deleting a group
  // TODO: add option to move memberships as well
  if ($form_id == 'node_delete_confirm') {
    $node = node_load($form['nid']['#value']);
    if (og_is_group_type($node->type)) {
      og_node_delete_group_form($form);
    }
    else {
      og_node_delete_nongroup_form($form);
    }
  }
  if ($form_id == 'views_edit_view') {
    $form['page-info']['url']['#description'] .= '<p>' . t("To display a View as a tab on your Organic Groups group home pages, set the url to 'node/\$group/custom' (where <em>custom</em> is whatever you wish). Then open Page >> Menu and check <em>Provide Menu</em> and <em>Provide Menu as Tab</em>; also make the first argument in the View be the <em>OG: Group nid(s)</em> argument. The <em>\$group</em> path element is a placeholder for the group nid and it ensures that the tab <strong>only</strong> appears on OG group nodes.") . '</p>';
  }
  if ($form_id == 'node_type_form') {

    // Built in content types do not alow changes to type machine name.
    if (isset($form['identity']['type']['#default_value'])) {
      $usage = variable_get('og_content_type_usage_' . $form['identity']['type']['#default_value'], 'omitted');
    }
    else {
      $usage = variable_get('og_content_type_usage_' . $form['identity']['type']['#value'], 'omitted');
    }

    // Persist $usage so that we can rebuild node access as needed.
    $form['old_og_content_type_usage'] = array(
      '#type' => 'value',
      '#value' => $usage,
    );
    $form['#submit']['og_node_type_form_submit'] = array();
    $options = og_types_map();
    $form['workflow']['og_content_type_usage'] = array(
      '#type' => 'radios',
      '#title' => t('Organic groups usage'),
      '#default_value' => $usage,
      '#options' => $options,
      '#description' => t('Specify how organic groups should treat nodes of this type. Nodes may behave as a group, as group posts, or may not participate in organic groups at all.'),
    );
  }
}