I need the equivalent of
domain_get_domain() in the Domain Access module for Drupal 8, but I can't find it.
I need to find the domain for the current request.
Finally worked out the following ...
$domainNegotiator = \Drupal::service('domain.negotiator'); $current = $domainNegotiator->negotiateActiveHostname();
There are other methods on the DomainNegotiator service that I thought should work, particularly
getActiveId(), but they didn't return the domain I was actually on like I thought they would.
It's still a bit confusing to me, but I made it work.
EDIT: @berramou 's answer below helped as well. Originally, I was looking for the Domain object (from the Domain Access module), but it turns out the host was enough to match a Domain reference on my entity.
In drupal 8 there is
\Drupal::request() to get request info.
For Example if your url something like
If you want only the domain name
$domain = \Drupal::request()->getHost();
if you want the domain name with schema
http or https
https://example.com use this:
$domain_with_schema = \Drupal::request()->getSchemeAndHttpHost();