DomainAliasListBuilder.php in Domain Access 8
File
domain_alias/src/DomainAliasListBuilder.php
View source
<?php
namespace Drupal\domain_alias;
use Drupal\domain\DomainInterface;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
class DomainAliasListBuilder extends ConfigEntityListBuilder {
protected $domain;
public function buildHeader() {
$header['label'] = $this
->t('Pattern');
$header['redirect'] = $this
->t('Redirect');
$header['environment'] = $this
->t('Environment');
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$row = [];
$row['label'] = $entity
->label();
$redirect = $entity
->getRedirect();
$row['redirect'] = empty($redirect) ? $this
->t('None') : $redirect;
$row['environment'] = $entity
->getEnvironment();
$row += parent::buildRow($entity);
return $row;
}
public function render() {
$build = [
'#theme' => 'table',
'#header' => $this
->buildHeader(),
'#rows' => [],
'#empty' => $this
->t('No aliases have been created for this domain.'),
];
foreach ($this
->load() as $entity) {
if ($row = $this
->buildRow($entity)) {
$build['#rows'][$entity
->id()] = $row;
}
}
return $build;
}
protected function getEntityIds() {
$query = $this
->getStorage()
->getQuery()
->condition('domain_id', $this
->getDomainId())
->sort($this->entityType
->getKey('id'));
if ($this->limit) {
$query
->pager($this->limit);
}
return $query
->execute();
}
public function setDomain(DomainInterface $domain) {
$this->domain = $domain;
}
public function getDomainId() {
return !empty($this->domain) ? $this->domain
->id() : NULL;
}
}