You are here

public function GeocoderProviderCreationForm::buildForm in Geocoder 8.3

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 FormInterface::buildForm

File

src/Form/GeocoderProviderCreationForm.php, line 69

Class

GeocoderProviderCreationForm
Provides a simple form that allows to select the provider type.

Namespace

Drupal\geocoder\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) : array {
  $providers = [];
  foreach ($this->pluginManager
    ->getDefinitions() as $id => $definition) {
    $providers[$id] = $definition['name'];
  }
  asort($providers);
  $form['header']['#markup'] = '<h3>' . $this
    ->t('Add a Geocoder provider') . '</h3>';
  $form['container'] = [
    '#type' => 'container',
    '#attributes' => [
      'class' => [
        'container-inline',
      ],
    ],
    '#open' => TRUE,
  ];
  $form['container']['geocoder_provider'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Geocoder provider plugin'),
    '#title_display' => 'invisible',
    '#options' => $providers,
    '#empty_option' => $this
      ->t('- Select -'),
  ];
  $form['container']['actions'] = [
    '#type' => 'actions',
  ];
  $form['container']['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Add'),
  ];
  $providers = $this->link
    ->generate(t('list of all available Geocoder providers'), Url::fromUri('https://packagist.org/providers/geocoder-php/provider-implementation', [
    'absolute' => TRUE,
    'attributes' => [
      'target' => 'blank',
    ],
  ]));
  $form['help'] = [
    'caption' => [
      '#type' => 'html_tag',
      '#tag' => 'p',
      '#value' => $this
        ->t('If the provider of your choice does not appear in the dropdown, make sure that it is installed using Composer. Here is the @providers_list.', [
        '@providers_list' => $providers,
      ]),
    ],
  ];
  return $form;
}