You are here

public function GTranslateSettingsForm::buildForm in Translate Drupal with GTranslate 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 ConfigFormBase::buildForm

File

src/Form/GTranslateSettingsForm.php, line 36
Contains \Drupal\gtranslate\Form\GTranslateSettingsForm.

Class

GTranslateSettingsForm
Controller location for Live Weather Settings Form.

Namespace

Drupal\gtranslate\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('gtranslate.settings');
  $form['general'] = array(
    '#type' => 'details',
    '#title' => $this
      ->t('General Configuration'),
    '#open' => true,
  );
  $form['general']['gtranslate_look'] = array(
    '#type' => 'select',
    '#title' => $this
      ->t('Look'),
    '#default_value' => $config
      ->get('gtranslate_look'),
    '#size' => 1,
    '#options' => array(
      'flags_dropdown' => 'Flags and dropdown',
      'flags' => 'Flags',
      'dropdown' => 'Dropdown',
      'dropdown_with_flags' => 'Nice dropdown with flags',
    ),
    '#description' => $this
      ->t("Select the look of the module"),
    '#required' => TRUE,
  );
  $form['general']['gtranslate_main_lang'] = array(
    '#type' => 'select',
    '#title' => $this
      ->t('Main Language'),
    '#default_value' => $config
      ->get('gtranslate_main_lang'),
    '#size' => 1,
    '#options' => $this->languages,
    '#description' => $this
      ->t("Your sites main language"),
    '#required' => TRUE,
  );
  $form['general']['gtranslate_pro'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Sub-directory URL structure'),
    '#default_value' => $config
      ->get('gtranslate_pro'),
    '#description' => $this
      ->t('Example: http://example.com/<b>ru</b>/. This feature is available only in paid plans: <a href="https://gtranslate.io/?xyz=1002#pricing" target="_blank">https://gtranslate.io/#pricing</a>'),
  );
  $form['general']['gtranslate_enterprise'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Sub-domain URL structure'),
    '#default_value' => $config
      ->get('gtranslate_enterprise'),
    '#description' => $this
      ->t('Example: http://<b>es.</b>example.com/. This feature is available only in paid plans: <a href="https://gtranslate.io/?xyz=1002#pricing" target="_blank">https://gtranslate.io/#pricing</a>'),
  );
  $form['general']['gtranslate_flag_size'] = array(
    '#type' => 'radios',
    '#title' => $this
      ->t('Flag Size'),
    '#default_value' => $config
      ->get('gtranslate_flag_size'),
    '#options' => array(
      16 => '16px',
      24 => '24px',
      32 => '32px',
    ),
    '#description' => $this
      ->t("Select the flag size"),
    '#required' => TRUE,
  );
  $form['general']['gtranslate_new_window'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Open translated page in a new window'),
    '#default_value' => $config
      ->get('gtranslate_new_window'),
    '#description' => $this
      ->t("The translated page will appear in a new window"),
  );
  $form['general']['gtranslate_analytics'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Analytics'),
    '#default_value' => $config
      ->get('gtranslate_analytics'),
    '#description' => $this
      ->t("If you have Google Analytics _gaq code on your site you can enable this which will allow you to see translation events in Google Analytics -&gt; Content -&gt; Event Tracking."),
  );
  $form['language'] = array(
    '#type' => 'details',
    '#title' => $this
      ->t('Language Configuration'),
  );
  foreach ($this->languages as $lang => $language) {
    $form['language']["gtranslate_{$lang}"] = array(
      '#type' => 'radios',
      '#title' => $this
        ->t("Show {$language}"),
      '#default_value' => $config
        ->get('gtranslate_' . $lang, 0),
      '#options' => array(
        1 => 'Yes',
        0 => 'No',
        2 => 'As a flag',
      ),
      '#description' => $this
        ->t("Show {$language} in the language list"),
      '#required' => TRUE,
    );
  }
  return parent::buildForm($form, $form_state);
}