public function WebformLocationBase::form in Webform 8.5
Same name and namespace in other branches
- 6.x src/Plugin/WebformElement/WebformLocationBase.php \Drupal\webform\Plugin\WebformElement\WebformLocationBase::form()
 
Gets the actual configuration webform array to be built.
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 An associative array contain the element's configuration webform without any default values.
Overrides WebformCompositeBase::form
2 calls to WebformLocationBase::form()
- WebformLocationGeocomplete::form in modules/
webform_location_geocomplete/ src/ Plugin/ WebformElement/ WebformLocationGeocomplete.php  - Gets the actual configuration webform array to be built.
 - WebformLocationPlaces::form in src/
Plugin/ WebformElement/ WebformLocationPlaces.php  - Gets the actual configuration webform array to be built.
 
2 methods override WebformLocationBase::form()
- WebformLocationGeocomplete::form in modules/
webform_location_geocomplete/ src/ Plugin/ WebformElement/ WebformLocationGeocomplete.php  - Gets the actual configuration webform array to be built.
 - WebformLocationPlaces::form in src/
Plugin/ WebformElement/ WebformLocationPlaces.php  - Gets the actual configuration webform array to be built.
 
File
- src/
Plugin/ WebformElement/ WebformLocationBase.php, line 79  
Class
- WebformLocationBase
 - Provides a base 'location' element.
 
Namespace
Drupal\webform\Plugin\WebformElementCode
public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $form['composite']['geolocation'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t("Use the browser's Geolocation as the default value"),
    '#description' => $this
      ->t('The <a href="https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API">HTML Geolocation API</a> is used to get the geographical position of a user. Since this can compromise privacy, the position is not available unless the user approves it.'),
    '#return_value' => TRUE,
  ];
  $form['composite']['hidden'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t("Hide the location element and collect the browser's Geolocation in the background"),
    '#return_value' => TRUE,
    '#states' => [
      'visible' => [
        ':input[name="properties[geolocation]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  // Reverted #required label.
  $form['validation']['required']['#description'] = $this
    ->t('Check this option if the user must enter a value.');
  return $form;
}