public function WundergroundWeatherSettingsForm::buildForm in Wunderground weather 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/ WundergroundWeatherSettingsForm.php, line 88 - Contains \Drupal\wunderground_weather\Form\wunderground_weatherSettingsForm.
Class
- WundergroundWeatherSettingsForm
- Defines a form to configure module settings.
Namespace
Drupal\wunderground_weather\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
// Get all settings.
$config = $this->configFactory
->get('wunderground_weather.settings');
$form['settings'] = [
'#tree' => TRUE,
];
// Link to get the api key.
$api_url = 'http://www.wunderground.com/weather/api';
$url = Url::fromUri($api_url);
$wg_link = $this->linkGenerator
->generate($api_url, $url);
$form['api_key'] = [
'#type' => 'textfield',
'#title' => t('Wunderground API key'),
'#description' => t('Get your API key at @url', [
'@url' => $wg_link,
]),
'#default_value' => $config
->get('api_key'),
'#required' => TRUE,
];
$form['language'] = [
'#type' => 'select',
'#title' => t('Language'),
'#options' => $this
->getLanguages(),
'#default_value' => $config
->get('language'),
];
return parent::buildForm($form, $form_state);
}