You are here

public function ConfigEntityFormBase::buildForm in Flags 8

Overrides Drupal\Core\Entity\EntityFormController::form().

Builds the entity add/edit form.

Parameters

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

FormStateInterface $form_state: An instance of FormStateInterface containing the current state of the form.

Return value

array An associative array containing the FlagMapping add/edit form.

Overrides EntityForm::buildForm

1 call to ConfigEntityFormBase::buildForm()
CountryMappingEditForm::buildForm in flags_ui/src/Form/CountryMappingEditForm.php
@inheritDoc
1 method overrides ConfigEntityFormBase::buildForm()
CountryMappingEditForm::buildForm in flags_ui/src/Form/CountryMappingEditForm.php
@inheritDoc

File

flags_ui/src/Form/ConfigEntityFormBase.php, line 81

Class

ConfigEntityFormBase
Class ConfigEntityFormBase.

Namespace

Drupal\flags_ui\Form

Code

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

  // Get anything we need from the base class.
  $form = parent::buildForm($form, $form_state);

  // Drupal provides the entity to us as a class variable. If this is an
  // existing entity, it will be populated with existing values as class
  // variables. If this is a new entity, it will be a new object with the
  // class of our entity. Drupal knows which class to call from the
  // annotation on our FlagMapping class.

  /** @var FlagMapping $mapping */
  $mapping = $this->entity;

  // Build the form.
  $form['source'] = $this
    ->getSourceFormItem($mapping);
  if (\Drupal::moduleHandler()
    ->moduleExists('select_icons')) {
    $mapper = \Drupal::service('flags.mapping.language');
    $attributes = $mapper
      ->getOptionAttributes((array) array_keys($this->flags));
    $form['flag'] = [
      '#type' => 'select_icons',
      '#options_attributes' => $attributes,
      '#attached' => array(
        'library' => array(
          'flags/flags',
        ),
      ),
    ];
  }
  else {
    $form['flag']['#type'] = 'select';
  }
  $form['flag'] += [
    '#title' => $this
      ->t('Flag'),
    '#options' => $this->flags,
    '#empty_value' => '',
    '#default_value' => $mapping
      ->getFlag(),
    '#description' => $this
      ->t('Select a target flag.'),
    '#required' => TRUE,
  ];

  // Return the form.
  return $form;
}