You are here

public function StyledGoogleMapSettingsForm::buildForm in Styled Google Map 8.2

Same name and namespace in other branches
  1. 8 src/Form/styledGoogleMapSettingsForm.php \Drupal\styled_google_map\Form\styledGoogleMapSettingsForm::buildForm()

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 ConfigFormBase::buildForm

File

src/Form/StyledGoogleMapSettingsForm.php, line 62

Class

StyledGoogleMapSettingsForm
Configure example settings for this site.

Namespace

Drupal\styled_google_map\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('styled_google_map.settings');
  $form['styled_google_map_google_auth_method'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Google API Authentication Method'),
    '#options' => [
      StyledGoogleMapInterface::STYLED_GOOGLE_MAP_GOOGLE_AUTH_KEY => t('API Key'),
      StyledGoogleMapInterface::STYLED_GOOGLE_MAP_GOOGLE_AUTH_WORK => t('Google Maps API for Work'),
    ],
    '#default_value' => $config
      ->get('styled_google_map_google_auth_method'),
  ];
  $form['styled_google_map_google_apikey'] = [
    '#type' => 'textfield',
    '#title' => t('Google Maps API Key'),
    '#description' => $this
      ->t('Obtain a Google Maps Javascript API key at <a href="@link">@link</a>', [
      '@link' => 'https://developers.google.com/maps/documentation/javascript/get-api-key',
    ]),
    '#default_value' => $config
      ->get('styled_google_map_google_apikey'),
    '#required' => FALSE,
    '#states' => [
      'visible' => [
        ':input[name="styled_google_map_google_auth_method"]' => [
          'value' => StyledGoogleMapInterface::STYLED_GOOGLE_MAP_GOOGLE_AUTH_KEY,
        ],
      ],
    ],
  ];
  $form['styled_google_map_google_client_id'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Google Maps API for Work: Client ID'),
    '#description' => $this
      ->t('For more information, visit: <a href="@link">@link</a>', [
      '@link' => 'https://developers.google.com/maps/documentation/javascript/get-api-key#client-id',
    ]),
    '#default_value' => $config
      ->get('styled_google_map_google_client_id'),
    '#required' => FALSE,
    '#states' => [
      'visible' => [
        ':input[name="styled_google_map_google_auth_method"]' => [
          'value' => StyledGoogleMapInterface::STYLED_GOOGLE_MAP_GOOGLE_AUTH_WORK,
        ],
      ],
    ],
  ];
  $form['styled_google_map_libraries'] = [
    '#type' => 'checkboxes',
    '#options' => [
      'drawing' => $this
        ->t('Drawing'),
      'geometry' => $this
        ->t('Geometry'),
      'localContext' => $this
        ->t('Local Context'),
      'places' => $this
        ->t('Places'),
    ],
    '#default_value' => $config
      ->get('styled_google_map_libraries'),
    '#title' => $this
      ->t('Additional libraries to load with Google Map'),
    '#description' => $this
      ->t('Read more <a href="@url" target="_blank">here</a>. "visualization" library is already included', [
      '@url' => 'https://developers.google.com/maps/documentation/javascript/libraries',
    ]),
  ];
  return parent::buildForm($form, $form_state);
}