You are here

class GeolocationGoogleMapInput in Geolocation Field 8

Provides a one-line text field form element.

Plugin annotation

@FormElement("geolocation_google_map_input");

Hierarchy

Expanded class hierarchy of GeolocationGoogleMapInput

1 #type use of GeolocationGoogleMapInput
DemoFormElement::buildForm in modules/geolocation_demo/src/Form/DemoFormElement.php
Form constructor.

File

src/Element/GeolocationGoogleMapInput.php, line 13

Namespace

Drupal\geolocation\Element
View source
class GeolocationGoogleMapInput extends GeolocationGoogleMap implements FormElementInterface {

  /**
   * {@inheritdoc}
   */
  public function getInfo() {
    $get_info = parent::getInfo();
    unset($get_info['#pre_render']);
    $get_info['#input'] = TRUE;
    $get_info['#max_locations'] = 1;
    $get_info['#process'] = [
      [
        $this,
        'processMapInputElement',
      ],
    ];
    $get_info['#theme_wrappers'] = [
      'container',
    ];
    $get_info['#attributes']['class'] = [
      'geolocation-google-map-form-element',
    ];
    $get_info['#attached']['library'] = [
      'geolocation/geolocation.google_map_form_element',
    ];
    return $get_info;
  }

  /**
   * {@inheritdoc}
   */
  public static function valueCallback(&$element, $input, FormStateInterface $form_state) {
    return $input;
  }

  /**
   * Mapping input.
   *
   * @param array $element
   *   Element.
   *
   * @return array
   *   Renderable form element.
   */
  public function processMapInputElement(array &$element) {
    $element['#tree'] = TRUE;
    $max_locations = 1;
    if (!empty($element['#max_locations'])) {
      $max_locations = (int) $element['#max_locations'];
    }
    if (!empty($element['#locations'])) {
      $element['#locations'] = array_splice($element['#locations'], 0, $max_locations);
    }
    $element['geolocation_map'] = $this
      ->preRenderGoogleMapElement($element);
    $element['#theme_wrappers']['container']['#attributes']['id'] = 'geolocation-google-map-form-element-' . $element['geolocation_map']['#uniqueid'];
    $element['#attached']['drupalSettings'] = [
      'geolocation' => [
        'googleMapFormElements' => [
          $element['geolocation_map']['#uniqueid'] => [
            'maxLocations' => $max_locations,
          ],
        ],
      ],
    ];
    for ($i = 0; $i < $max_locations; $i++) {
      $element['geolocation_map_input_' . $i] = [
        '#type' => 'fieldset',
        '#attributes' => [
          'class' => [
            'geolocation-map-input',
            'geolocation-map-input-' . $i,
          ],
        ],
        'latitude' => [
          '#type' => 'textfield',
          '#title' => $this
            ->t('Latitude'),
          '#attributes' => [
            'class' => [
              'geolocation-map-input-latitude',
            ],
          ],
          '#value' => empty($element['#locations'][$i]) ? '' : $element['#locations'][$i]['latitude'],
        ],
        'longitude' => [
          '#type' => 'textfield',
          '#title' => $this
            ->t('Longitude'),
          '#attributes' => [
            'class' => [
              'geolocation-map-input-longitude',
            ],
          ],
          '#value' => empty($element['#locations'][$i]) ? '' : $element['#locations'][$i]['longitude'],
        ],
      ];
      if (!empty($element['#title'])) {
        if ($max_locations > 1) {
          $element['geolocation_map_input_' . $i]['#title'] = $element['#title'] . ' #' . $i;
        }
        else {
          $element['geolocation_map_input_' . $i]['#title'] = $element['#title'];
        }
      }
    }
    return $element;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
GeolocationGoogleMap::preRenderGoogleMapElement public function Map element.
GeolocationGoogleMapInput::getInfo public function Returns the element properties for this element. Overrides GeolocationGoogleMap::getInfo
GeolocationGoogleMapInput::processMapInputElement public function Mapping input.
GeolocationGoogleMapInput::valueCallback public static function Determines how user input is mapped to an element's #value property. Overrides FormElementInterface::valueCallback
GoogleMapsDisplayTrait::$GOOGLEMAPSAPIURL public static property Google maps url with default parameters.
GoogleMapsDisplayTrait::$HYBRID public static property Google map style - Hybrid.
GoogleMapsDisplayTrait::$MAXZOOMLEVEL public static property Google map max zoom level.
GoogleMapsDisplayTrait::$MINZOOMLEVEL public static property Google map min zoom level.
GoogleMapsDisplayTrait::$ROADMAP public static property Google map style - Roadmap.
GoogleMapsDisplayTrait::$SATELLITE public static property Google map style - Satellite.
GoogleMapsDisplayTrait::$TERRAIN public static property Google map style - Terrain.
GoogleMapsDisplayTrait::getGoogleMapDefaultSettings public static function Provide a populated settings array.
GoogleMapsDisplayTrait::getGoogleMapsApiParameters public function Return all module and custom defined parameters.
GoogleMapsDisplayTrait::getGoogleMapsApiUrl public function Return the fully build URL to load Google Maps API.
GoogleMapsDisplayTrait::getGoogleMapsSettings public function Provide settings ready to handover to JS to feed to Google Maps.
GoogleMapsDisplayTrait::getGoogleMapsSettingsForm public function Provide a generic map settings form array.
GoogleMapsDisplayTrait::getGoogleMapsSettingsSummary public function Provide a summary array to use in field formatters.
GoogleMapsDisplayTrait::getMapTypes private function An array of all available map types.
GoogleMapsDisplayTrait::validateGoogleMapsSettingsForm public function Validate the form elements defined above.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. 92
RenderElement::preRenderAjaxForm public static function Adds Ajax information about an element to communicate with JavaScript.
RenderElement::preRenderGroup public static function Adds members of this group as actual elements for rendering.
RenderElement::processAjaxForm public static function Form element processing handler for the #ajax form property. 1
RenderElement::processGroup public static function Arranges elements into groups.
RenderElement::setAttributes public static function Sets a form element's class attribute. Overrides ElementInterface::setAttributes
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.