public function DomainListBuilder::getOperations in Domain Access 8
Provides an array of information to build a list of operation links.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity the operations are for.
Return value
array An associative array of operation link data for this list, keyed by operation name, containing the following key-value pairs:
- title: The localized title of the operation.
- url: An instance of \Drupal\Core\Url for the operation URL.
- weight: The weight of this operation.
Overrides EntityListBuilder::getOperations
File
- domain/
src/ DomainListBuilder.php, line 143
Class
- DomainListBuilder
- User interface for the domain overview screen.
Namespace
Drupal\domainCode
public function getOperations(EntityInterface $entity) {
$operations = parent::getOperations($entity);
$destination = $this->destinationHandler
->getAsArray();
$default = $entity
->isDefault();
$id = $entity
->id();
// If the user cannot edit domains, none of these actions are permitted.
$access = $this->accessHandler
->checkAccess($entity, 'update');
if ($access
->isForbidden()) {
return $operations;
}
$super_admin = $this->currentUser
->hasPermission('administer domains');
if ($super_admin || $this->currentUser
->hasPermission('access inactive domains')) {
if ($entity
->status() && !$default) {
$operations['disable'] = [
'title' => $this
->t('Disable'),
'url' => Url::fromRoute('domain.inline_action', [
'op' => 'disable',
'domain' => $id,
]),
'weight' => 50,
];
}
elseif (!$default) {
$operations['enable'] = [
'title' => $this
->t('Enable'),
'url' => Url::fromRoute('domain.inline_action', [
'op' => 'enable',
'domain' => $id,
]),
'weight' => 40,
];
}
}
if (!$default && $super_admin) {
$operations['default'] = [
'title' => $this
->t('Make default'),
'url' => Url::fromRoute('domain.inline_action', [
'op' => 'default',
'domain' => $id,
]),
'weight' => 30,
];
}
if (!$default && $this->accessHandler
->checkAccess($entity, 'delete')
->isAllowed()) {
$operations['delete'] = [
'title' => $this
->t('Delete'),
'url' => Url::fromRoute('entity.domain.delete_form', [
'domain' => $id,
]),
'weight' => 20,
];
}
$operations += $this->moduleHandler
->invokeAll('domain_operations', [
$entity,
$this->currentUser,
]);
foreach ($operations as $key => $value) {
if (isset($value['query']['token'])) {
$operations[$key]['query'] += $destination;
}
}
/** @var DomainInterface $default */
$default = $this->domainStorage
->loadDefaultDomain();
// Deleting the site default domain is not allowed.
if ($default && $id == $default
->id()) {
unset($operations['delete']);
}
return $operations;
}