You are here

function course_form_node_type_form_alter in Course 6

Same name and namespace in other branches
  1. 8.3 course.module \course_form_node_type_form_alter()
  2. 8.2 course.module \course_form_node_type_form_alter()
  3. 7.2 course.module \course_form_node_type_form_alter()
  4. 7 course.module \course_form_node_type_form_alter()
  5. 3.x course.module \course_form_node_type_form_alter()

Implements hook_form_FORM_ID_alter().

File

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

Code

function course_form_node_type_form_alter(&$form, &$form_state) {

  // Alter the node type's configuration form to add our setting.
  $form['course'] = array(
    '#type' => 'fieldset',
    '#title' => t('Course settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#access' => user_access('administer course'),
    '#group' => TRUE,
  );
  $form['course']['course_use'] = array(
    '#title' => t('Use as course type'),
    '#type' => 'checkbox',
    '#default_value' => variable_get("course_use_{$form['#node_type']->type}", 0),
  );

  // Ctools dependency.
  ctools_include('dependent');
  $dependent = array(
    '#process' => array(
      'ctools_dependent_process',
    ),
    '#dependency' => array(
      'edit-course-use' => array(
        1,
      ),
    ),
  );

  // Configurable date fields.
  if (module_exists('date')) {
    $options = array();
    $options[0] = t('<Not specified>');
    $fields = content_fields();
    foreach ($fields as $field) {
      if ($field['module'] == 'date') {
        foreach ($field['columns'] as $column => $value) {
          if (in_array($column, array(
            'value',
            'value2',
          ))) {
            $position = $column == 'value' ? 'From' : 'To';

            // Use the same label pattern as date_api_fields() for consistency
            // with Views, and in case we support other date options than
            // content date fields.
            $label = t('Content: !label (!name) - @position date', array(
              '!label' => $field['widget']['label'],
              '!name' => $field['field_name'],
              '@position' => $position,
            ));

            #$key = "{$field['field_name']}[0]['{$column}']";
            $key = serialize(array(
              'field' => $field['field_name'],
              'value' => $column,
            ));
            $options[$key] = $label;
          }
        }
      }
    }

    // Enduring course dates.
    $form['course']['course_start_date'] = array(
      '#title' => t('Field to use for enduring-course start date'),
      '#description' => t('Select the field to use for enduring-course start date.'),
      '#type' => 'select',
      '#options' => $options,
      '#default_value' => variable_get("course_start_date_{$form['#node_type']->type}", 0),
      '#prefix' => '<h3>' . t('Enduring course dates') . '</h3>',
    ) + $dependent;
    $form['course']['course_expiration_date'] = array(
      '#title' => t('Field to use for enduring-course expiration date'),
      '#description' => t('Select the field to use for enduring-course expiration date.'),
      '#type' => 'select',
      '#options' => $options,
      '#default_value' => variable_get("course_expiration_date_{$form['#node_type']->type}", 0),
    ) + $dependent;

    // Live course dates.
    $form['course']['course_live_from_date'] = array(
      '#title' => t('Field to use for live-course start date'),
      '#description' => t('Select the field to use for live-course start date.'),
      '#type' => 'select',
      '#options' => $options,
      '#default_value' => variable_get("course_live_from_date_{$form['#node_type']->type}", 0),
      '#prefix' => '<h3>' . t('Live course dates') . '</h3>',
    ) + $dependent;
    $form['course']['course_live_to_date'] = array(
      '#title' => t('Field to use for live-course end date'),
      '#description' => t('Select the field to use for live-course end date.'),
      '#type' => 'select',
      '#options' => $options,
      '#default_value' => variable_get("course_live_to_date_{$form['#node_type']->type}", 0),
    ) + $dependent;
  }
}