function drush_domain_add in Domain Access 8
Same name and namespace in other branches
- 7.3 domain.drush.inc \drush_domain_add()
Adds a new domain.
Parameters
string $hostname: The domain name to register.
string $name: The name to use for this domain.
File
- domain/
domain.drush.inc, line 315 - Drush commands for Domain Access.
Code
function drush_domain_add($hostname, $name) {
$records_count = \Drupal::entityTypeManager()
->getStorage('domain')
->getQuery()
->count()
->execute();
$start_weight = $records_count + 1;
$hostname = mb_strtolower($hostname);
/** @var \Drupal\domain\DomainStorageInterface $domain_storage */
$domain_storage = \Drupal::entityTypeManager()
->getStorage('domain');
$values = [
'hostname' => $hostname,
'name' => $name,
'status' => !drush_get_option('invalid') ? 1 : 0,
'scheme' => !drush_get_option('https') ? 'http' : 'https',
'weight' => ($weight = drush_get_option('weight')) ? $weight : $start_weight + 1,
'is_default' => ($is_default = drush_get_option('is_default')) ? $is_default : 0,
'id' => $domain_storage
->createMachineName($hostname),
'validate_url' => drush_get_option('validate') ? 1 : 0,
];
$domain = $domain_storage
->create($values);
domain_drush_create($domain);
}