You are here

function course_form_alter in Course 6

Implements hook_form_alter().

Course node settings form.

@todo move this course node settings form to a secondary local task, under the course settings tab.

File

./course.module, line 1171
course.module Core functionality for Courses.

Code

function course_form_alter(&$form, &$form_state, $form_id) {
  $node = isset($form['#node']) ? $form['#node'] : NULL;

  // Course node settings form.
  if (course_node_is_course($node) && strpos($form_id, '_node_form') !== FALSE) {
    $form['course']['#tree'] = TRUE;
    $form['course']['#type'] = 'fieldset';
    $form['course']['#title'] = t('Course settings');
    $form['course']['#group'] = TRUE;

    // Course outline display handler.
    $outlines = array();
    $handlers = course_get_handlers('outline');
    foreach ($handlers as $outline_handlers) {
      if ($outline_handlers) {
        foreach ($outline_handlers as $key => $outline_handler) {
          $outlines[$key] = $outline_handler['name'];
        }
      }
    }
    $form['course']['outline'] = array(
      '#title' => t('Available outline displays'),
      '#type' => 'select',
      '#options' => $outlines,
    );

    // This is a fake field. It stores the aggregate credit from course_credit.
    // @todo...something
    $form['course']['credits'] = array(
      '#title' => t('Credit hours'),
      '#type' => 'textfield',
      '#size' => 4,
      '#access' => FALSE,
    );
    if (module_exists('date')) {
      $open = variable_get('course_start_date_' . $node->type, array());
      $close = variable_get('course_expiration_date_' . $node->type, array());
      $form['course']['open'] = array(
        '#title' => t('Release date'),
        '#type' => module_exists('date_popup') ? 'date_popup' : 'date_text',
        '#access' => empty($open['field']),
      );
      $form['course']['close'] = array(
        '#title' => t('Expiration date'),
        '#type' => module_exists('date_popup') ? 'date_popup' : 'date_text',
        '#access' => empty($close['field']),
      );
    }
    $form['course']['duration'] = array(
      '#title' => t('Duration'),
      '#type' => 'textfield',
      '#size' => 4,
      '#description' => t('Length in days a user can remain in the course. Enter 0 for unlimited.'),
    );
    $form['course']['cid'] = array(
      '#title' => t('External learning application course ID'),
      '#description' => t('If using an external learning application, the ID of the external course.'),
      '#type' => 'textfield',
      '#size' => 4,
      '#access' => FALSE,
    );
    $form['course']['external_id'] = array(
      '#title' => t('External course ID'),
      '#description' => t('Course ID used to relate to an outside system.'),
      '#type' => 'textfield',
      '#size' => 16,
    );
    foreach (element_children($form['course']) as $key) {
      $form['course'][$key]['#default_value'] = isset($node->course[$key]) ? $node->course[$key] : NULL;
    }
    if (arg(2) == 'clone') {
      $form['course']['clone_type'] = array(
        '#title' => t('Course object cloning'),
        '#description' => t('"New" will create new instances of all course objects.<br/>"Reference" will link supported content in the old course to the new course.<br/>"Clone" will copy supported course objects, otherwise create new ones.'),
        '#type' => 'radios',
        '#options' => array(
          'clone' => 'Clone',
          'reference' => 'Reference',
          'new' => 'New',
        ),
        '#default_value' => 'clone',
      );
    }

    // After creating a new course, redirect the user to the course outline
    // overview form.
    if (empty($node->nid)) {
      $form['buttons']['submit']['#submit'][] = 'course_form_submit';
    }
  }
  if (strpos($form_id, 'views_bulk_operations_form') === 0 && strpos($_GET['q'], 'admin/reports/course/overview/select') === 0) {
    $form['url']['#default_value'] = url('admin/reports/course/overview/view', array(
      'absolute' => TRUE,
    ));
    $form['url']['#type'] = 'hidden';
  }
}