You are here

public function PollForm::form in Poll 8

Gets the actual form array to be built.

Overrides ContentEntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

src/Form/PollForm.php, line 16

Class

PollForm
Form controller for the poll edit forms.

Namespace

Drupal\poll\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $poll = $this->entity;
  if ($poll
    ->isNew()) {
    $title = $this
      ->t('Add new poll');
  }
  else {
    $title = $this
      ->t('Edit @label', [
      '@label' => $poll
        ->label(),
    ]);
  }
  $form['#title'] = $title;
  foreach ($form['choice']['widget'] as $key => $choice) {
    if (is_int($key) && $form['choice']['widget'][$key]['choice']['#default_value'] != NULL) {
      $form['choice']['widget'][$key]['choice']['#attributes'] = [
        'class' => [
          'poll-existing-choice',
        ],
      ];
    }
  }
  $form['#attached'] = [
    'library' => [
      'poll/admin',
    ],
  ];
  return $form;
}