function course_field_attach_form in Course 7
Same name and namespace in other branches
- 7.2 course.module \course_field_attach_form()
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 1021 - course.module Core functionality for Courses.
Code
function course_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode) {
if ($entity_type == 'node' && course_node_is_course($entity)) {
$form['course']['#tree'] = TRUE;
$form['course']['#type'] = 'fieldset';
$form['course']['#title'] = t('Course settings');
// 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('Outline display'),
'#type' => 'select',
'#options' => $outlines,
'#default_value' => variable_get('default_lms_' . $entity->type, NULL),
'#description' => t('This controls the presentation of the course objects.'),
);
$enrollment_types = course_enrollment_types();
foreach ($enrollment_types as $enrollment_type => $type_info) {
$enrollment_type_options[$enrollment_type] = $type_info->label;
}
$form['course']['enrollment_type'] = array(
'#title' => t('Enrollment type'),
'#type' => 'select',
'#options' => $enrollment_type_options,
'#default_value' => isset($entity->course['enrollment_type']) ? $entity->course['enrollment_type'] : NULL,
'#description' => t("The enrollment type's fields, if required for enrollment, will be presented to the user before starting the course."),
);
// This is a simple credit hours field. If course_credit is enabled it used
// for storing the maximum credit of any credit instance.
if (!module_exists('course_credit')) {
$form['course']['credits'] = array(
'#title' => t('Credits'),
'#type' => 'textfield',
'#size' => 4,
'#description' => t('For more advanced crediting, use the !link module.', array(
'!link' => l('Course credit', 'http://drupal.org/project/course_credit'),
)),
);
}
$form['course']['duration'] = array(
'#title' => t('Duration'),
'#type' => 'textfield',
'#description' => t('Length of time in seconds that a user can remain in the course. Leave blank for unlimited.<br/>For a better experience, install the !link module.', array(
'!link' => l('Time period', 'http://drupal.org/project/timeperiod'),
)),
);
if (module_exists('timeperiod')) {
$form['course']['duration']['#type'] = 'timeperiod_select';
$form['course']['duration']['#units'] = array(
'86400' => array(
'max' => 30,
'step size' => 1,
),
'3600' => array(
'max' => 24,
'step size' => 1,
),
'60' => array(
'max' => 60,
'step size' => 1,
),
);
$form['course']['duration']['#description'] = t('Length of time that a user can remain in the course.');
}
$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) {
if (isset($entity->course[$key])) {
$form['course'][$key]['#default_value'] = $entity->course[$key];
}
}
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($entity->nid)) {
$form['actions']['submit']['#submit'][] = 'course_form_submit';
}
}
}