You are here

public function MappingEditForm::form in GatherContent 8.4

Same name and namespace in other branches
  1. 8.5 gathercontent_ui/src/Form/MappingEditForm.php \Drupal\gathercontent_ui\Form\MappingEditForm::form()

Gets the actual form array to be built.

Overrides EntityForm::form

See also

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

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

File

gathercontent_ui/src/Form/MappingEditForm.php, line 66

Class

MappingEditForm
Class MappingEditForm.

Namespace

Drupal\gathercontent_ui\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  if (empty($this->step)) {
    $this->step = 'field_mapping';
  }
  $form['#attached']['library'][] = 'gathercontent_ui/theme';
  $form['#attached']['library'][] = 'gathercontent_ui/entity_references';

  /** @var \Drupal\gathercontent\Entity\MappingInterface $mapping */
  $mapping = $this->entity;
  $this->new = !$mapping
    ->hasMapping();
  $template = $this->client
    ->templateGet($mapping
    ->getGathercontentTemplateId());
  if ($this->step === 'field_mapping') {
    if (!$this->new) {
      $this->mappingStep = $this->mappingService
        ->getEditStep($mapping, $template);
    }
    else {
      $this->mappingStep = $this->mappingService
        ->getNewStep($mapping, $template);
    }
  }
  elseif ($this->step === 'er_mapping') {

    // Unset previous form.
    foreach ($form as $k => $item) {
      if (!in_array($k, [
        '#attributes',
        '#cache',
      ])) {
        unset($form[$k]);
      }
    }
    $this->mappingStep = $this->mappingService
      ->getEntityReferenceStep($mapping, $template);
    $this->mappingStep
      ->setErImportType($this->erImportType);
    $this->step = 'completed';
  }
  $form = $form + $this->mappingStep
    ->getForm($form_state);
  $this
    ->setEntityReferenceFields($this->mappingStep
    ->getEntityReferenceFields());
  $this
    ->setEntityReferenceFieldsOptions($this->mappingStep
    ->getEntityReferenceFieldsOptions());
  $form['#attached']['drupalSettings']['gathercontent'] = $this->entityReferenceFieldsOptions;
  return $form;
}