You are here

public function DemoFormElement::buildForm in Geolocation Field 8

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

modules/geolocation_demo/src/Form/DemoFormElement.php, line 23

Class

DemoFormElement
Returns responses for geolocation_demo module routes.

Namespace

Drupal\geolocation_demo\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['geolocation_map_input'] = [
    '#type' => 'geolocation_google_map_input',
    '#title' => $this
      ->t('Simple Location Input'),
    '#latitude' => 40.67,
    '#longitude' => -73.94,
    '#height' => 120,
  ];
  $form['geolocation_map_input_code'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Location Input Code'),
    'code' => [
      '#type' => 'html_tag',
      '#tag' => 'pre',
      '#value' => '
        $elements[\'geolocation_map_input\'] = [
          \'#type\' => \'geolocation_google_map_input\',
          \'#title\' => $this->t(\'Simple Location Input\'),
          \'#latitude\' => 40.6700,
          \'#longitude\' => -73.9400,
          \'#height\' => 120,
        ];
        ',
    ],
  ];
  $form['geolocation_map_input_complex'] = [
    '#type' => 'geolocation_google_map_input',
    '#title' => $this
      ->t('Complex Location Input'),
    '#height' => 320,
    '#controls' => TRUE,
    '#max_locations' => 2,
    '#locations' => [
      [
        'latitude' => 6.8,
        'longitude' => -1.616667,
      ],
      [
        'latitude' => 6.6,
        'longitude' => -1.616667,
      ],
    ],
  ];
  $form['geolocation_map_input_complex_code'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Complex Location Input Code'),
    'code' => [
      '#type' => 'html_tag',
      '#tag' => 'pre',
      '#value' => '
        $form[\'geolocation_map_input_complex\'] = [
          \'#type\' => \'geolocation_google_map_input\',
          \'#title\' => $this->t(\'Complex Location Input\'),
          \'#height\' => 320,
          \'#controls\' => TRUE,
          \'#max_locations\' => 2,
          \'#locations\' => [
            [
              \'latitude\' => 6.8,
              \'longitude\' => -1.616667,
            ],
            [
              \'latitude\' => 6.6,
              \'longitude\' => -1.616667,
            ],
          ],
        ];
        ',
    ],
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Submit test form'),
  ];
  return $form;
}