public function Domain::saveDefault in Domain Access 8
Makes a domain record the default.
Overrides DomainInterface::saveDefault
File
- domain/
src/ Entity/ Domain.php, line 211
Class
- Domain
- Defines the domain entity.
Namespace
Drupal\domain\EntityCode
public function saveDefault() {
if (!$this
->isDefault()) {
// Swap the current default.
/** @var self $default */
if ($default = \Drupal::entityTypeManager()
->getStorage('domain')
->loadDefaultDomain()) {
$default->is_default = FALSE;
$default
->setHostname($default
->getCanonical());
$default
->save();
}
// Save the new default.
$this->is_default = TRUE;
$this
->setHostname($this
->getCanonical());
$this
->save();
}
else {
\Drupal::messenger()
->addMessage($this
->t('The selected domain is already the default.'), 'warning');
}
}