You are here

public function WSFieldConfigForm::form in Web Service Data 8

Same name and namespace in other branches
  1. 2.0.x modules/wsdata_field/src/Form/WSFieldConfigForm.php \Drupal\wsdata_field\Form\WSFieldConfigForm::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

modules/wsdata_field/src/Form/WSFieldConfigForm.php, line 79

Class

WSFieldConfigForm
Class WSFieldsConfigForm.

Namespace

Drupal\wsdata_field\Form

Code

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

  // Load the field configurations.
  $field_config = $form_state
    ->get('field_config');
  if ($this->entityTypeManager
    ->getStorage('wsfield_config')
    ->load($field_config
    ->get('field_name')) == NULL) {
    $wsfield_config_entity = $this->entity;
  }
  else {
    $this->entity = $this->entityTypeManager
      ->getStorage('wsfield_config')
      ->load($field_config
      ->get('field_name'));
    $wsfield_config_entity = $this->entity;
  }

  // Set the title.
  $form['#title'] = $this
    ->t('Web service field settings');

  // Set the ID as the field name.
  $form['id'] = [
    '#type' => 'hidden',
    '#value' => $field_config
      ->get('field_name'),
  ];
  $wsfield_config = [
    'wscall' => $wsfield_config_entity->wscall,
    'replacements' => $wsfield_config_entity->replacements,
    'data' => $wsfield_config_entity->data,
    'returnToken' => $wsfield_config_entity->returnToken,
    'languageHandling' => $wsfield_config_entity->languageHandling ?? 'entityLanguage',
  ];
  $wscall = $wsfield_config_entity->wscall;
  $form_state_wscall = $form_state
    ->getValue('wscall');
  if (isset($form_state_wscall)) {
    $wscall = $form_state_wscall;
  }
  $elements = $this->wsdata
    ->wscallForm($wsfield_config, $wscall);
  $form = array_merge($form, $elements);
  $form['replacements']['token_tree'] = [
    '#theme' => 'token_tree_link',
    '#token_types' => [
      'node',
    ],
    '#show_restricted' => TRUE,
    '#weight' => 90,
  ];
  $form['languageHandling'] = [
    '#title' => $this
      ->t('Language handling'),
    '#description' => $this
      ->t('Which language is used to retrieve field values'),
    '#type' => 'select',
    '#default_value' => $wsfield_config['languageHandling'],
    '#options' => [
      'entityLanguage' => $this
        ->t('Entity language'),
      'interfaceLanguage' => $this
        ->t('Interface language'),
    ],
  ];
  return $form;
}