public function CourseObjectNode::optionsForm in Course 3.x
Same name and namespace in other branches
- 8.3 modules/course_content/src/Course/Object/CourseObjectNode.php \Drupal\course_content\Course\Object\CourseObjectNode::optionsForm()
- 8.2 modules/course_content/src/Course/Object/CourseObjectNode.php \Drupal\course_content\Course\Object\CourseObjectNode::optionsForm()
Default options form for all course objects.
Overrides CourseObject::optionsForm
1 call to CourseObjectNode::optionsForm()
- CourseObjectBook::optionsForm in modules/
course_book/ src/ Plugin/ course/ CourseObject/ CourseObjectBook.php - Default options form for all course objects.
1 method overrides CourseObjectNode::optionsForm()
- CourseObjectBook::optionsForm in modules/
course_book/ src/ Plugin/ course/ CourseObject/ CourseObjectBook.php - Default options form for all course objects.
File
- modules/
course_content/ src/ Course/ Object/ CourseObjectNode.php, line 165
Class
- CourseObjectNode
- A course object that uses a node as a base.
Namespace
Drupal\course_content\Course\ObjectCode
public function optionsForm(&$form, FormStateInterface $form_state) {
parent::optionsForm($form, $form_state);
$form['node'] = array(
'#type' => 'details',
'#title' => t('Content'),
'#description' => 'Settings for course object content.',
'#group' => 'course_tabs',
'#weight' => 2,
);
$config = $this
->getOptions();
$types = array_combine($this
->getNodeTypes(), $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' => (bool) $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'),
'#type' => 'entity_autocomplete',
'#target_type' => 'node',
'#selection_settings' => [
'target_bundles' => $this
->getNodeTypes(),
],
'#description' => t('Use existing content instead of creating a new one.'),
'#default_value' => !empty($this
->getInstanceId()) ? $this
->getNode() : NULL,
'#maxlength' => 255,
'#states' => array(
'visible' => array(
':input[name="use_existing_node"]' => array(
'checked' => TRUE,
),
),
),
'#weight' => 3,
);
if (Drupal::moduleHandler()
->moduleExists('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);
$url = Url::fromRoute('entity.node.canonical', [
'node' => $node
->id(),
], array(
'attributes' => array(
'target' => '_blank',
'title' => t('Open in new window'),
),
));
$link = Link::fromTextAndUrl(t("'%title' [node id %nid]", array(
'%title' => $node
->get('title')
->getString(),
'%nid' => $node
->id(),
)), $url)
->toString();
$form['node']['instance']['#description'] = t('Currently set to @link', array(
'@link' => $link,
));
}
}