You are here

public function LiveWeatherController::locationList in Live Weather 8.2

Same name and namespace in other branches
  1. 8 src/Controller/LiveWeatherController.php \Drupal\live_weather\Controller\LiveWeatherController::locationList()

Constructs a list of locations.

1 string reference to 'LiveWeatherController::locationList'
live_weather.routing.yml in ./live_weather.routing.yml
live_weather.routing.yml

File

src/Controller/LiveWeatherController.php, line 57

Class

LiveWeatherController
Controller for live_weather WOEID settings.

Namespace

Drupal\live_weather\Controller

Code

public function locationList() {
  $rows = $build = [];
  $location_list = $this->configFactory
    ->get('live_weather.location')
    ->get('location');
  $form_arg = 'Drupal\\live_weather\\Form\\LiveWeatherForm';
  $build['live_weather_form'] = $this->formBuilder
    ->getForm($form_arg);
  $header = [
    $this
      ->t('Woeid'),
    $this
      ->t('Location'),
    [
      'data' => $this
        ->t('Operations'),
      'colspan' => 2,
    ],
  ];
  if (!empty($location_list)) {
    foreach ($location_list as $key => $value) {
      $operations = [];
      $operations['delete'] = [
        'title' => $this
          ->t('Delete'),
        'url' => Url::fromRoute('live_weather.delete', [
          'woeid' => $key,
        ]),
      ];
      $data['woeid'] = $key;
      $data['location'] = Html::escape($value);
      $data['operations'] = [
        'data' => [
          '#type' => 'operations',
          '#links' => $operations,
        ],
      ];
      $rows[] = $data;
    }
  }
  $build['live_weather_table'] = [
    '#type' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => $this
      ->t('No locations available.'),
  ];
  return $build;
}