public function DomainCommands::doReassign in Domain Access 8
Handles reassignment of entities to another domain.
This method includes necessary UI elements if the user is prompted to choose a new domain.
Parameters
Drupal\domain\DomainInterface $target_domain: The domain selected for deletion.
array $delete_options: A selection of options for deletion, defined in reassignLinkedEntities().
3 calls to DomainCommands::doReassign()
- DomainAccessCommands::domainAccessDomainDelete in domain_access/
src/ Commands/ DomainAccessCommands.php - @hook on-event domain-delete
- DomainCommands::delete in domain/
src/ Commands/ DomainCommands.php - Delete a domain from the site.
- DomainSourceCommands::domainSourceDomainDelete in domain_source/
src/ Commands/ DomainSourceCommands.php - @hook on-event domain-delete
File
- domain/
src/ Commands/ DomainCommands.php, line 514
Class
- DomainCommands
- Drush commands for the domain module.
Namespace
Drupal\domain\CommandsCode
public function doReassign(DomainInterface $target_domain, array $delete_options) {
$policy = $delete_options['policy'];
$default_domain = $this
->domainStorage()
->loadDefaultDomain();
$all_domains = $this
->domainStorage()
->loadMultipleSorted(NULL);
// Perform the 'prompt' for a destination domain.
if ($policy === 'prompt') {
// Make a list of the eligible destination domains in form id -> name.
$noassign_domain = [
$target_domain
->id(),
];
$reassign_list = $this
->filterDomains($all_domains, $noassign_domain);
$reassign_base = [
'ignore' => dt('Do not reassign'),
'default' => dt('Reassign to default domain'),
];
$reassign_list = array_map(function (DomainInterface $d) {
return $d
->getHostname();
}, $reassign_list);
$reassign_list = array_merge($reassign_base, $reassign_list);
$policy = $this
->io()
->choice(dt('Reassign @type field @field data to:', [
'@type' => $delete_options['entity_filter'],
'@field' => $delete_options['field'],
]), $reassign_list);
}
elseif ($policy === 'default') {
$policy = $default_domain
->id();
}
if ($policy !== 'ignore') {
$delete_options['policy'] = $policy;
$target = [
$target_domain,
];
$count = $this
->reassignLinkedEntities($target, $delete_options);
return dt('@count @type entities updated field @field.', [
'@count' => $count,
'@type' => $delete_options['entity_filter'],
'@field' => $delete_options['field'],
]);
}
}