You are here

public function CourseObjectNode::optionsForm in Course 7.2

Same name and namespace in other branches
  1. 6 includes/course_object.core.inc \CourseObjectNode::optionsForm()
  2. 7 includes/CourseObjectNode.inc \CourseObjectNode::optionsForm()

Default options form for all course objects.

Overrides CourseObject::optionsForm

5 calls to CourseObjectNode::optionsForm()
CourseObjectBook::optionsForm in modules/course_book/course_book.classes.inc
Default options form for all course objects.
CourseObjectContent::optionsForm in modules/course_content/course_content.classes.inc
Set the default content type to be created.
CourseObjectQuiz::optionsForm in modules/course_quiz/course_quiz.classes.inc
Add an option only pertinent to quiz?
CourseObjectSignup::optionsForm in modules/course_signup/course_signup.classes.inc
Default options form for all course objects.
CourseObjectUbercart::optionsForm in modules/course_uc/course_uc.classes.inc
Default options form for all course objects.
5 methods override CourseObjectNode::optionsForm()
CourseObjectBook::optionsForm in modules/course_book/course_book.classes.inc
Default options form for all course objects.
CourseObjectContent::optionsForm in modules/course_content/course_content.classes.inc
Set the default content type to be created.
CourseObjectQuiz::optionsForm in modules/course_quiz/course_quiz.classes.inc
Add an option only pertinent to quiz?
CourseObjectSignup::optionsForm in modules/course_signup/course_signup.classes.inc
Default options form for all course objects.
CourseObjectUbercart::optionsForm in modules/course_uc/course_uc.classes.inc
Default options form for all course objects.

File

includes/CourseObjectNode.inc, line 135

Class

CourseObjectNode
A course object that uses a node as a base.

Code

public function optionsForm(&$form, &$form_state) {
  parent::optionsForm($form, $form_state);
  $form['node'] = array(
    '#type' => 'fieldset',
    '#title' => t('Content'),
    '#description' => 'Settings for course object content.',
    '#group' => 'course_tabs',
    '#weight' => 2,
  );
  $config = $this
    ->getOptions();
  $types = drupal_map_assoc($this
    ->getNodeTypes());
  $options = array_intersect_key(node_type_get_names(), $types);
  $form['node']['use_existing_node'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use existing content'),
    '#default_value' => $this
      ->getOption('use_existing_node'),
    '#weight' => 1,
    '#access' => $this
      ->isTemporary(),
  );
  $form['node']['node_type'] = array(
    '#title' => t('Create node'),
    '#type' => 'select',
    '#options' => $options,
    '#description' => t('Selecting a node type will automatically create this node and link it to this course object.'),
    '#default_value' => $config['node_type'],
    '#states' => array(
      'visible' => array(
        ':input[name="use_existing_node"]' => array(
          'checked' => FALSE,
        ),
      ),
    ),
    '#weight' => 2,
    '#access' => $this
      ->isTemporary(),
  );
  if (count($options) > 1) {
    $form['node']['node_type']['#required'] = TRUE;
  }
  $form['node']['instance'] = array(
    '#title' => t('Existing content'),
    '#autocomplete_path' => 'course/autocomplete/node/' . implode(',', $this
      ->getNodeTypes()),
    '#type' => 'textfield',
    '#description' => t('Use existing content instead of creating a new one.'),
    '#default_value' => !empty($this
      ->getInstanceId()) ? check_plain($this
      ->getNode()->title) . " [nid: {$this->getInstanceId()}]" : NULL,
    '#maxlength' => 255,
    '#states' => array(
      'visible' => array(
        ':input[name="use_existing_node"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
    '#weight' => 3,
  );
  if (module_exists('clone') && !$this
    ->getInstanceId()) {
    $form['node']['clone_and_reference'] = array(
      '#title' => t('Clone and reference'),
      '#type' => 'checkbox',
      '#description' => t('This will clone the selected content first.'),
      '#default_value' => $config['clone_and_reference'],
      '#weight' => 4,
      '#states' => array(
        'visible' => array(
          ':input[name="use_existing_node"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
  }
  $form['node']['use_node_title'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use existing title'),
    '#description' => t("Use the referenced content's title as this course object's title."),
    '#default_value' => $config['use_node_title'],
    '#weight' => 5,
  );
  $form['node']['private'] = array(
    '#title' => t('Private'),
    '#description' => $this
      ->hasNodePrivacySupport() ? t('This content will not be available to users who are not enrolled in this course.') : t('You must enable content_access and acl in order to restrict course content to users who are enrolled in this course.'),
    '#type' => 'checkbox',
    '#default_value' => $config['private'],
    '#disabled' => !$this
      ->hasNodePrivacySupport(),
    '#weight' => 6,
  );
  $nid = $this
    ->getInstanceId();
  if ($nid) {
    $node = node_load($nid);
    $link = l(t("'%title' [node id %nid]", array(
      '%title' => $node->title,
      '%nid' => $node->nid,
    )), "node/{$node->nid}", array(
      'attributes' => array(
        'target' => '_blank',
        'title' => t('Open in new window'),
      ),
      'html' => TRUE,
    ));
    $form['node']['instance']['#description'] = t('Currently set to !link', array(
      '!link' => $link,
    ));
  }

  // Block deletion of self-referencing node instances.
  if (!empty($config['instance']) && $config['instance'] == $this
    ->getCourseNid()) {
    $form['delete']['delete_instance']['#disabled'] = TRUE;
    $form['delete']['delete_instance']['#description'] = t('You cannot delete this instance, as it references this Course.');
  }
}