You are here

public function styledGoogleMapSettingsForm::buildForm in Styled Google Map 8

Same name and namespace in other branches
  1. 8.2 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 31

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'] = array(
    '#type' => 'select',
    '#title' => $this
      ->t('Google API Authentication Method'),
    '#options' => array(
      STYLED_GOOGLE_MAP_GOOGLE_AUTH_KEY => t('API Key'),
      STYLED_GOOGLE_MAP_GOOGLE_AUTH_WORK => t('Google Maps API for Work'),
    ),
    '#default_value' => $config
      ->get('styled_google_map_google_auth_method', STYLED_GOOGLE_MAP_GOOGLE_AUTH_KEY),
  );
  $form['styled_google_map_google_apikey'] = array(
    '#type' => 'textfield',
    '#title' => t('Google Maps API Key'),
    '#description' => $this
      ->t('Obtain a Google Maps Javascript API key at <a href="@link">@link</a>', array(
      '@link' => 'https://developers.google.com/maps/documentation/javascript/get-api-key',
    )),
    '#default_value' => $config
      ->get('styled_google_map_google_apikey', ''),
    '#required' => FALSE,
    '#states' => array(
      'visible' => array(
        ':input[name="styled_google_map_google_auth_method"]' => array(
          'value' => STYLED_GOOGLE_MAP_GOOGLE_AUTH_KEY,
        ),
      ),
    ),
  );
  $form['styled_google_map_google_client_id'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Google Maps API for Work: Client ID'),
    '#description' => $this
      ->t('For more information, visit: <a href="@link">@link</a>', array(
      '@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' => array(
      'visible' => array(
        ':input[name="styled_google_map_google_auth_method"]' => array(
          'value' => STYLED_GOOGLE_MAP_GOOGLE_AUTH_WORK,
        ),
      ),
    ),
  );
  return parent::buildForm($form, $form_state);
}