You are here

public function DomainSiteSettingsController::domainList in Domain Site Settings 8

Function Provide the list of modules.

Return value

array Domain list.

1 string reference to 'DomainSiteSettingsController::domainList'
domain_site_settings.routing.yml in ./domain_site_settings.routing.yml
domain_site_settings.routing.yml

File

src/Controller/DomainSiteSettingsController.php, line 22

Class

DomainSiteSettingsController
Lists all domains for which we can edit the settings.

Namespace

Drupal\domain_site_settings\Controller

Code

public function domainList() {
  $domains = $this
    ->entityTypeManager()
    ->getStorage('domain')
    ->loadMultiple();
  $rows = [];

  /** @var \Drupal\domain\DomainInterface $domain */
  foreach ($domains as $domain) {
    $row = [
      $domain
        ->label(),
      $domain
        ->getCanonical(),
      Link::fromTextAndUrl($this
        ->t('Edit'), Url::fromRoute('domain_site_settings.config_form', [
        'domain' => $domain
          ->id(),
      ])),
    ];
    $rows[] = $row;
  }

  // Build a render array which will be themed as a table.
  $build['pager_example'] = [
    '#rows' => $rows,
    '#header' => [
      $this
        ->t('Name'),
      $this
        ->t('Hostname'),
      $this
        ->t('Edit Settings'),
    ],
    '#type' => 'table',
    '#empty' => $this
      ->t('No domain record found.'),
  ];
  return $build;
}