CourseObjectForm.php in Course 8.2
File
src/Form/CourseObjectForm.php
View source
<?php
namespace Drupal\course\Form;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use function course_get_course_object_by_id;
class CourseObjectForm extends FormBase {
public function buildForm(array $form, FormStateInterface $form_state, $course = NULL, $course_object = NULL) {
$form = array();
if (!($courseObject = _course_get_course_object_by_uniqid($course_object))) {
$courseObject = \Drupal\course\Entity\CourseObject::load($course_object);
}
$form[$courseObject
->getComponent()] = array(
'#title' => $courseObject
->getComponentName(),
'#type' => 'details',
'#group' => 'course_tabs',
'#description' => t('Configuration for @name course objects.', array(
'@name' => $courseObject
->getComponentName(),
)),
'#weight' => 2,
);
$courseObject
->optionsForm($form, $form_state);
$form_display = EntityFormDisplay::collectRenderDisplay($courseObject, 'default');
$form_display
->buildForm($courseObject, $form, $form_state);
foreach (Element::children($form) as $key) {
$element = $form[$key];
if (!empty($element['#type']) && $element['#type'] == 'container') {
$form['title'][$key] = $element;
unset($form[$key]);
}
}
$fieldset_key = $courseObject
->getComponent();
foreach (Element::children($form) as $key) {
$element = $form[$key];
if (!empty($element['#type']) && !in_array($element['#type'], array(
'',
'hidden',
'details',
'submit',
'button',
'fieldset',
'vertical_tabs',
'value',
))) {
$form[$fieldset_key][$key] = $element;
unset($form[$key]);
}
}
return $form;
}
public function getFormId() {
return 'course_object_options_form';
}
public function submitForm(array &$form, FormStateInterface $form_state) {
}
}