You are here

public function DomainCommands::infoDomains in Domain Access 8

List general information about the domains on the site.

@usage drush domain:info

@command domain:info @aliases domain-info,dinf

@field-labels count: All Domains count_active: Active Domains default_id: Default Domain ID default_host: Default Domain hostname scheme: Fields in Domain entity domain_admin_entities: Domain admin entities @list-orientation true @format table

Return value

\Consolidation\OutputFormatters\StructuredData\PropertyList A structured list of domain information.

Throws

\Drupal\domain\Commands\DomainCommandException

File

domain/src/Commands/DomainCommands.php, line 182

Class

DomainCommands
Drush commands for the domain module.

Namespace

Drupal\domain\Commands

Code

public function infoDomains() {
  $default_domain = $this
    ->domainStorage()
    ->loadDefaultDomain();

  // Load all domains:
  $all_domains = $this
    ->domainStorage()
    ->loadMultiple(NULL);
  $active_domains = [];
  foreach ($all_domains as $domain) {
    if ($domain
      ->status()) {
      $active_domains[] = $domain;
    }
  }
  $keys = [
    'count',
    'count_active',
    'default_id',
    'default_host',
    'scheme',
  ];
  $rows = [];
  foreach ($keys as $key) {
    $v = '';
    switch ($key) {
      case 'count':
        $v = count($all_domains);
        break;
      case 'count_active':
        $v = count($active_domains);
        break;
      case 'default_id':
        $v = '-unset-';
        if ($default_domain) {
          $v = $default_domain
            ->id();
        }
        break;
      case 'default_host':
        $v = '-unset-';
        if ($default_domain) {
          $v = $default_domain
            ->getHostname();
        }
        break;
      case 'scheme':
        $v = implode(', ', array_keys($this
          ->domainStorage()
          ->loadSchema()));
        break;
    }
    $rows[$key] = $v;
  }

  // Display which entities are enabled for domain by checking for the fields.
  $rows['domain_admin_entities'] = $this
    ->getFieldEntities(DomainInterface::DOMAIN_ADMIN_FIELD);
  return new PropertyList($rows);
}