You are here

public function FlaggingCollectionForm::buildForm in Flag Lists 8

Same name and namespace in other branches
  1. 4.0.x src/Form/FlaggingCollectionForm.php \Drupal\flag_lists\Form\FlaggingCollectionForm::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/FlaggingCollectionForm.php, line 19

Class

FlaggingCollectionForm
Form controller for Flagging collection edit forms.

Namespace

Drupal\flag_lists\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  /* @var $entity \Drupal\flag_lists\Entity\FlaggingCollection */
  $form = parent::buildForm($form, $form_state);
  $flaglistService = \Drupal::service('flaglists');
  $account = \Drupal::currentUser();
  $entity = $this->entity;
  $existing_flaglists = $flaglistService
    ->getAllFlagForList(NULL, NULL);
  $options = [];
  foreach ($existing_flaglists as $flaglist) {
    if ($flaglist
      ->hasBaseFlag()) {
      $options[$flaglist
        ->get('id')] = $flaglist
        ->label();
    }
  }
  $current_value = empty($entity
    ->getBaseFlag()) ? FALSE : $entity
    ->getBaseFlag()
    ->id();
  $form['templateflag'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Template flag'),
    '#required' => TRUE,
    '#options' => $options,
    '#default_value' => $current_value,
  ];
  return $form;
}