You are here

public function CourseManageForm::buildForm in Course 8.3

Same name and namespace in other branches
  1. 8.2 src/Form/CourseManageForm.php \Drupal\course\Form\CourseManageForm::buildForm()
  2. 3.x src/Form/CourseManageForm.php \Drupal\course\Form\CourseManageForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

src/Form/CourseManageForm.php, line 20

Class

CourseManageForm

Namespace

Drupal\course\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, Drupal\course\Entity\Course $course = NULL) {
  $collection = 'config.entity.key_store.course';
  $name = 'course:' . $course
    ->id();
  $kv = Drupal::keyValue($collection);
  $course_settings = $kv
    ->get($name);
  $form['status'] = [
    '#title' => $this
      ->t('Enrollments are'),
    '#type' => 'select',
    '#options' => [
      1 => t('Open'),
      0 => t('Closed'),
    ],
    '#default_value' => $course_settings['status'],
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => t('Save'),
  ];
  return $form;
}