public function DomainAliasTestTrait::createDomainAlias in Domain Access 8
Creates an alias.
Parameters
array $values: An array of values to assign to the alias.
bool $save: Whether to save the alias or return for validation.
Return value
\Drupal\domain_alias\Entity\DomainAlias A domain alias entity.
6 calls to DomainAliasTestTrait::createDomainAlias()
- DomainAliasActionsTest::testDomainActions in domain_alias/
tests/ src/ Functional/ DomainAliasActionsTest.php - Tests bulk actions through the domain overview page.
- DomainAliasDomainDeleteTest::testDomainDelete in domain_alias/
tests/ src/ Kernel/ DomainAliasDomainDeleteTest.php - Tests alias deletion on domain deletion.
- DomainAliasEnvironmentTest::testDomainAliasEnvironments in domain_alias/
tests/ src/ Functional/ DomainAliasEnvironmentTest.php - Test for environment matching.
- DomainAliasListHostnameTest::testDomainAliasEnvironments in domain_alias/
tests/ src/ Functional/ DomainAliasListHostnameTest.php - Test for environment matching.
- DomainAliasTestTrait::domainAliasCreateTestAlias in domain_alias/
tests/ src/ Traits/ DomainAliasTestTrait.php - Creates an alias for testing without passing values.
File
- domain_alias/
tests/ src/ Traits/ DomainAliasTestTrait.php, line 23
Class
- DomainAliasTestTrait
- Contains helper classes for tests to set up various configuration.
Namespace
Drupal\Tests\domain_alias\TraitsCode
public function createDomainAlias(array $values, $save = TRUE) {
// Replicate the logic for creating machine_name patterns.
// @see ConfigBase::validate()
$machine_name = mb_strtolower(preg_replace('/[^a-z0-9_]/', '_', $values['pattern']));
$values['id'] = str_replace([
'*',
'.',
':',
], '_', $machine_name);
$alias = \Drupal::entityTypeManager()
->getStorage('domain_alias')
->create($values);
if ($save) {
$alias
->save();
}
return $alias;
}