protected function SettingsForm::addWeatherDisplayOverview in Weather 8
Same name and namespace in other branches
- 2.0.x src/Form/SettingsForm.php \Drupal\weather\Form\SettingsForm::addWeatherDisplayOverview()
Builds system wide weather displays overview.
1 call to SettingsForm::addWeatherDisplayOverview()
- SettingsForm::buildForm in src/
Form/ SettingsForm.php - Form constructor.
File
- src/
Form/ SettingsForm.php, line 145
Class
- SettingsForm
- Configure Weather settings for this site.
Namespace
Drupal\weather\FormCode
protected function addWeatherDisplayOverview(array &$form, FormStateInterface $form_state) {
$displays = $this->weatherDisplayStorage
->loadByProperties([
'type' => WeatherDisplayInterface::SYSTEM_WIDE_TYPE,
]);
foreach ($displays as $display) {
$display_number = $display->number->value;
$form['system_displays'][$display_number] = [
'#type' => 'table',
'#header' => [
Link::fromTextAndUrl($this
->t('System-wide display (#@number)', [
'@number' => $display_number,
]), Url::fromRoute('entity.weather_display.edit_form', [
'display_number' => $display_number,
])),
$this
->t('Weight'),
],
];
$locations = $this->weatherDisplayPlaceStorage
->getQuery()
->condition('display_type', WeatherDisplayInterface::SYSTEM_WIDE_TYPE)
->condition('display_number', $display_number)
->sort('weight', 'ASC')
->sort('displayed_name', 'ASC')
->execute();
foreach ($locations as $locationId) {
$location = $this->weatherDisplayPlaceStorage
->load($locationId);
$form['system_displays'][$display_number]['#rows'][] = [
Link::fromTextAndUrl($location->displayed_name->value, Url::fromRoute('entity.weather_display_place.edit_form', [
'display_type' => $location->display_type->value,
'display_number' => $display_number,
'weather_display_place' => $locationId,
])),
$location->weight->value,
];
}
// Insert link for adding locations into the table as last row.
$form['system_displays'][$display_number]['#rows'][] = [
'link' => Link::fromTextAndUrl($this
->t('Add location to this display'), Url::fromRoute('entity.weather_display_place.add_form', [
'display_type' => WeatherDisplayInterface::SYSTEM_WIDE_TYPE,
'display_number' => $display_number,
])),
'#wrapper_attributes' => [
'colspan' => 2,
],
];
}
}