CourseObjectForm.php in Course 3.x
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 Drupal\course\Entity\CourseObject;
use function _course_get_course_object_by_uniqid;
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 = 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) {
}
}