You are here

public function GeocoderBase::formAttachGeocoder in Geolocation Field 8.2

Same name and namespace in other branches
  1. 8.3 src/GeocoderBase.php \Drupal\geolocation\GeocoderBase::formAttachGeocoder()
  2. 8 src/GeocoderBase.php \Drupal\geolocation\GeocoderBase::formAttachGeocoder()

Attach geocoding logic to input element.

Parameters

array $render_array: Form containing the input element.

string $element_name: Name of the input element.

Return value

array|null Updated form element or NULL.

Overrides GeocoderInterface::formAttachGeocoder

3 calls to GeocoderBase::formAttachGeocoder()
GoogleGeocoderBase::formAttachGeocoder in modules/geolocation_google_maps/src/GoogleGeocoderBase.php
Attach geocoding logic to input element.
Photon::formAttachGeocoder in modules/geolocation_leaflet/src/Plugin/geolocation/Geocoder/Photon.php
Attach geocoding logic to input element.
Yandex::formAttachGeocoder in modules/geolocation_yandex/src/Plugin/geolocation/Geocoder/Yandex.php
Attach geocoding logic to input element.
4 methods override GeocoderBase::formAttachGeocoder()
Dummy::formAttachGeocoder in tests/modules/geolocation_dummy_geocoder/src/Plugin/geolocation/Geocoder/Dummy.php
Attach geocoding logic to input element.
GoogleGeocoderBase::formAttachGeocoder in modules/geolocation_google_maps/src/GoogleGeocoderBase.php
Attach geocoding logic to input element.
Photon::formAttachGeocoder in modules/geolocation_leaflet/src/Plugin/geolocation/Geocoder/Photon.php
Attach geocoding logic to input element.
Yandex::formAttachGeocoder in modules/geolocation_yandex/src/Plugin/geolocation/Geocoder/Yandex.php
Attach geocoding logic to input element.

File

src/GeocoderBase.php, line 109

Class

GeocoderBase
Class GeocoderBase.

Namespace

Drupal\geolocation

Code

public function formAttachGeocoder(array &$render_array, $element_name) {
  $settings = $this
    ->getSettings();
  $render_array['geolocation_geocoder_address'] = [
    '#type' => 'search',
    '#title' => $settings['label'] ?: $this
      ->t('Address'),
    '#placeholder' => $settings['label'] ?: $this
      ->t('Address'),
    '#description' => $settings['description'] ?: $this
      ->t('Enter an address to retrieve location.'),
    '#description_display' => 'after',
    '#maxlength' => 256,
    '#size' => 25,
    '#attributes' => [
      'class' => [
        'geolocation-geocoder-address',
        'form-autocomplete',
      ],
      'data-source-identifier' => $element_name,
    ],
    '#attached' => [
      'drupalSettings' => [
        'geolocation' => [
          'geocoder' => [
            $this
              ->getPluginId() => [
              'inputIds' => [
                $element_name,
              ],
            ],
          ],
        ],
      ],
    ],
  ];
}