diff core/modules/hal/src/LinkManager/LinkManagerBase.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents 4c8ae668cc8c
children
line wrap: on
line diff
--- a/core/modules/hal/src/LinkManager/LinkManagerBase.php	Mon Apr 23 09:33:26 2018 +0100
+++ b/core/modules/hal/src/LinkManager/LinkManagerBase.php	Mon Apr 23 09:46:53 2018 +0100
@@ -2,6 +2,8 @@
 
 namespace Drupal\hal\LinkManager;
 
+use Drupal\serialization\Normalizer\CacheableNormalizerInterface;
+
 /**
  * Defines an abstract base-class for HAL link manager objects.
  */
@@ -39,17 +41,32 @@
   /**
    * Gets the link domain.
    *
+   * @param array $context
+   *   Normalization/serialization context.
+   *
    * @return string
    *   The link domain.
+   *
+   * @see \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize()
+   * @see \Symfony\Component\Serializer\SerializerInterface::serialize()
+   * @see \Drupal\serialization\Normalizer\CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY
    */
-  protected function getLinkDomain() {
+  protected function getLinkDomain(array $context = []) {
     if (empty($this->linkDomain)) {
       if ($domain = $this->configFactory->get('hal.settings')->get('link_domain')) {
-        $this->linkDomain = rtrim($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();
-        $this->linkDomain = $request->getSchemeAndHttpHost() . $request->getBasePath();
+        return $request->getSchemeAndHttpHost() . $request->getBasePath();
       }
     }
     return $this->linkDomain;