function LinkManagerBase::getLinkDomain

Same name and namespace in other branches
  1. 8.9.x core/modules/hal/src/LinkManager/LinkManagerBase.php \Drupal\hal\LinkManager\LinkManagerBase::getLinkDomain()

Gets the link domain.

Parameters

array $context: Normalization/serialization context.

Return value

string The link domain.

See also

\Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize()

\Symfony\Component\Serializer\SerializerInterface::serialize()

\Drupal\serialization\Normalizer\CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY

File

core/modules/hal/src/LinkManager/LinkManagerBase.php, line 54

Class

LinkManagerBase
Defines an abstract base-class for HAL link manager objects.

Namespace

Drupal\hal\LinkManager

Code

protected function getLinkDomain(array $context = []) {
  if (empty($this->linkDomain)) {
    if ($domain = $this->configFactory
      ->get('hal.settings')
      ->get('link_domain')) {
      // Bubble the appropriate cacheability metadata whenever possible.
      if (isset($context[CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY])) {
        $context[CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY]->addCacheableDependency($this->configFactory
          ->get('hal.settings'));
      }
      return rtrim($domain, '/');
    }
    else {
      // Bubble the relevant cacheability metadata whenever possible.
      if (isset($context[CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY])) {
        $context[CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY]->addCacheContexts([
          'url.site',
        ]);
      }
      $request = $this->requestStack
        ->getCurrentRequest();
      return $request->getSchemeAndHttpHost() . $request->getBasePath();
    }
  }
  return $this->linkDomain;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.