You are here

public static function YamlFormLocation::getCompositeElements in YAML Form 8

Same name in this branch
  1. 8 src/Element/YamlFormLocation.php \Drupal\yamlform\Element\YamlFormLocation::getCompositeElements()
  2. 8 src/Plugin/YamlFormElement/YamlFormLocation.php \Drupal\yamlform\Plugin\YamlFormElement\YamlFormLocation::getCompositeElements()

Get a renderable array of form elements.

Return value

array A renderable array of form elements, containing the base properties for the composite's form elements.

Overrides YamlFormCompositeBase::getCompositeElements

2 calls to YamlFormLocation::getCompositeElements()
YamlFormLocation::getCompositeElements in src/Plugin/YamlFormElement/YamlFormLocation.php
Get composite elements.
YamlFormLocation::processYamlFormComposite in src/Element/YamlFormLocation.php
Processes a composite form element.

File

src/Element/YamlFormLocation.php, line 28

Class

YamlFormLocation
Provides a form element for a location element.

Namespace

Drupal\yamlform\Element

Code

public static function getCompositeElements() {

  // @see https://developers.google.com/maps/documentation/javascript/geocoding#GeocodingAddressTypes
  $attributes = [];
  $attributes['lat'] = [
    '#title' => t('Latitude'),
  ];
  $attributes['lng'] = [
    '#title' => t('Longitude'),
  ];
  $attributes['location'] = [
    '#title' => t('Location'),
  ];
  $attributes['formatted_address'] = [
    '#title' => t('Formatted Address'),
  ];
  $attributes['street_address'] = [
    '#title' => t('Street Address'),
  ];
  $attributes['street_number'] = [
    '#title' => t('Street Number'),
  ];
  $attributes['postal_code'] = [
    '#title' => t('Postal Code'),
  ];
  $attributes['locality'] = [
    '#title' => t('Locality'),
  ];
  $attributes['sublocality'] = [
    '#title' => t('City'),
  ];
  $attributes['administrative_area_level_1'] = [
    '#title' => t('State/Province'),
  ];
  $attributes['country'] = [
    '#title' => t('Country'),
  ];
  $attributes['country_short'] = [
    '#title' => t('Country Code'),
  ];
  foreach ($attributes as $name => &$attribute_element) {
    $attribute_element['#type'] = 'textfield';
    $attribute_element['#attributes'] = [
      'data-yamlform-location-attribute' => $name,
    ];
  }
  $elements = [];
  $elements['value'] = [
    '#type' => 'textfield',
    '#title' => t('Address'),
    '#attributes' => [
      'class' => [
        'yamlform-location-geocomplete',
      ],
    ],
  ];
  $elements += $attributes;
  return $elements;
}