You are here

function spaces_casetracker_form_alter in Spaces 5

Same name and namespace in other branches
  1. 5.2 spaces_casetracker/spaces_casetracker.module \spaces_casetracker_form_alter()

Implementation of hook_form_alter()

File

spaces_casetracker/spaces_casetracker.module, line 57

Code

function spaces_casetracker_form_alter($form_id, &$form) {
  switch ($form_id) {
    case 'casetracker_basic_case_node_form':
    case 'comment_form':

      // Allow adding cases in batches
      if ($_GET['batch'] == 1) {
        $form['#redirect'] = array(
          'node/add/casetracker-basic-case',
          'batch=1',
        );
      }

      // Change the autocomplete callback to limit by group & Remove disallowed projects.
      if (isset($form['casetracker_project_information'])) {
        $pid = $form_id == 'casetracker_basic_case_node_form' ? 'pid' : 'prid';

        // "sigh." see casetracker_form_alter() for details.
        if (is_array($form['casetracker_project_information'][$pid]['#options'])) {
          foreach ($form['casetracker_project_information'][$pid]['#options'] as $key => $value) {
            $node = array(
              'nid' => $key,
              'type' => 'casetracker_basic_project',
            );
            $groups = og_get_node_groups((object) $node);
            if ($current_gid = spaces_gid()) {
              if (!array_key_exists($current_gid, $groups)) {
                unset($form['casetracker_project_information'][$pid]['#options'][$key]);
              }
            }
          }
          $form['casetracker_case_information']['assign_to']['#autocomplete_path'] = 'spaces/team/autocomplete/' . $current_gid;
        }
      }
      break;

    // Views filters
    // Handle exposed casetracker filters, sadly case tracker is dumb to og.
    case 'views_filters':
      switch ($form['#view_name']) {
        case 'spaces_cases_my':
        case 'spaces_cases_byproject':
        case 'spaces_cases_bycreated':
          unset($form['filter0']['#options']);
          $form['filter0']['#options'] = spaces_casetracker_project_options();
          break;
        case 'spaces_cases_byuser':
          unset($form['filter0']['#options']);
          $form['filter0']['#options'] = spaces_casetracker_user_options();
          break;
        case 'spaces_cases_filter':
          unset($form['filter0']['#options']);
          $form['filter0']['#options'] = spaces_casetracker_project_options();
          unset($form['filter1']['#options']);
          $form['filter1']['#options'] = spaces_casetracker_user_options();
          break;
      }
      break;
  }
}