You are here

public function ILTResultForm::buildForm in Opigno Instructor-led Trainings 8

Same name and namespace in other branches
  1. 3.x src/Form/ILTResultForm.php \Drupal\opigno_ilt\Form\ILTResultForm::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 EntityForm::buildForm

File

src/Form/ILTResultForm.php, line 23

Class

ILTResultForm
Provides a form for creating/editing a opigno_ilt_result entity.

Namespace

Drupal\opigno_ilt\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildForm($form, $form_state);

  /** @var \Drupal\opigno_ilt\ILTResultInterface $entity */
  $entity = $this->entity;
  $form['opigno_ilt'] = [
    '#type' => 'entity_autocomplete',
    '#target_type' => 'opigno_ilt',
    '#title' => $this
      ->t('Instructor-Led Training'),
    '#default_value' => $entity
      ->getILT(),
    '#required' => TRUE,
  ];
  $form['user_id'] = [
    '#type' => 'entity_autocomplete',
    '#title' => $this
      ->t('User'),
    '#target_type' => 'user',
    '#default_value' => $entity
      ->getUser(),
    '#required' => TRUE,
  ];
  $form['status'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Status'),
    '#options' => [
      0 => $this
        ->t('Absent'),
      1 => $this
        ->t('Attended'),
    ],
    '#default_value' => $entity
      ->getStatus(),
  ];
  $form['score'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Score'),
    '#min' => 0,
    '#max' => 100,
    '#step' => 1,
    '#default_value' => $entity
      ->getScore(),
  ];
  return $form;
}