function CourseOutlineForm::formObject in Course 8.3
Same name and namespace in other branches
- 8.2 src/Form/CourseOutlineForm.php \Drupal\course\Form\CourseOutlineForm::formObject()
- 3.x src/Form/CourseOutlineForm.php \Drupal\course\Form\CourseOutlineForm::formObject()
Form constructor for a course object.
To be re-used in listing and creating new course objects.
1 call to CourseOutlineForm::formObject()
- CourseOutlineForm::buildForm in src/
Form/ CourseOutlineForm.php - Form constructor.
File
- src/
Form/ CourseOutlineForm.php, line 280
Class
Namespace
Drupal\course\FormCode
function formObject($courseObject = NULL) {
$rform['#attributes']['class'][] = 'draggable';
$rform['#tree'] = TRUE;
$uniqid = $courseObject
->getId();
// Do not use prefix/suffix because markup only renders with a value, and we
// need the wrapper before the title is saved for ajax population after each
// settings modal update.
$title = $courseObject
->getTitle();
$rform['description']['title'] = array(
'#prefix' => '<div id="title-' . $uniqid . '">',
'#suffix' => '</div>',
'#type' => 'markup',
'#plain_text' => $title,
);
$rform['description']['summary'] = array(
'#prefix' => '<div id="summary-' . $uniqid . '">',
'#suffix' => '</div>',
'#theme' => 'item_list',
'#items' => $courseObject
->renderOptionsSummary(),
);
$handlers = course_get_handlers('object');
if (empty($handlers[$courseObject
->getOption('object_type')])) {
$show_object_name = t('Missing CourseObject handler for <br/><i>@t</i>', array(
'@t' => $courseObject
->getOption('object_type'),
));
}
else {
$show_object_name = $handlers[$courseObject
->getOption('object_type')]['label'];
}
$rform['object_type_show'] = array(
'#type' => 'markup',
'#markup' => Xss::filterAdmin($show_object_name),
);
// Placeholder for the settings link, it gets added after this function runs
// in course_outline_overview_form(). #value needs a space for the prefix and
// suffix to render.
// Settings link for saved objects.
$text = t('Settings');
$l_options = array(
'query' => array(
'destination' => "course/{$courseObject->getCourse()->id()}/outline",
),
'attributes' => [
'data-dialog-type' => 'modal',
'class' => 'use-ajax',
'data-dialog-options' => \Drupal\Component\Serialization\Json::encode([
'width' => 800,
]),
],
);
$url = Url::fromRoute('course.object.options', [
'course' => $courseObject
->getCourse()
->id(),
'course_object' => $uniqid,
], $l_options);
$rform['options']['#markup'] = Link::fromTextAndUrl($text, $url)
->toString();
$rform['weight'] = array(
'#title' => $this
->t('Weight for @title', [
'@title' => $title,
]),
'#type' => 'weight',
'#title_display' => 'invisible',
'#size' => 3,
'#delta' => 100,
'#default_value' => $courseObject
->getOption('weight'),
'#attributes' => array(
'class' => array(
'course-object-weight',
),
),
);
if ($courseObject
->getOption('delete')) {
$rform['#attributes']['class'][] = 'deleted';
}
return $rform;
}