I'm using the modules domain and domain_alias on Drupal 8.

I need to load all the aliases of a given domain.

I have tried the following without success:

$aliases = \Drupal::service('entity_type.manager')->getStorage('domain_alias')->loadByHostname('my.domain.com');

$aliases = \Drupal::entityTypeManager()->getStorage('domain_alias')->loadByProperties(['hostname' => 'my.domain.com']);

Got it.

The 'hostname' is not a property of the alias. The way to get the aliases is:

$aliases = \Drupal::entityTypeManager()->getStorage('domain_alias')->loadByProperties(['domain_id' => 'my_domain_id']);

Note that 'my_domain_id' is specific to the domain that you are trying to get the alias for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.