Mercurial > hg > isophonics-drupal-site
comparison 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 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
1 <?php | 1 <?php |
2 | 2 |
3 namespace Drupal\hal\LinkManager; | 3 namespace Drupal\hal\LinkManager; |
4 | |
5 use Drupal\serialization\Normalizer\CacheableNormalizerInterface; | |
4 | 6 |
5 /** | 7 /** |
6 * Defines an abstract base-class for HAL link manager objects. | 8 * Defines an abstract base-class for HAL link manager objects. |
7 */ | 9 */ |
8 abstract class LinkManagerBase { | 10 abstract class LinkManagerBase { |
37 } | 39 } |
38 | 40 |
39 /** | 41 /** |
40 * Gets the link domain. | 42 * Gets the link domain. |
41 * | 43 * |
44 * @param array $context | |
45 * Normalization/serialization context. | |
46 * | |
42 * @return string | 47 * @return string |
43 * The link domain. | 48 * The link domain. |
49 * | |
50 * @see \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize() | |
51 * @see \Symfony\Component\Serializer\SerializerInterface::serialize() | |
52 * @see \Drupal\serialization\Normalizer\CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY | |
44 */ | 53 */ |
45 protected function getLinkDomain() { | 54 protected function getLinkDomain(array $context = []) { |
46 if (empty($this->linkDomain)) { | 55 if (empty($this->linkDomain)) { |
47 if ($domain = $this->configFactory->get('hal.settings')->get('link_domain')) { | 56 if ($domain = $this->configFactory->get('hal.settings')->get('link_domain')) { |
48 $this->linkDomain = rtrim($domain, '/'); | 57 // Bubble the appropriate cacheability metadata whenever possible. |
58 if (isset($context[CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY])) { | |
59 $context[CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY]->addCacheableDependency($this->configFactory->get('hal.settings')); | |
60 } | |
61 return rtrim($domain, '/'); | |
49 } | 62 } |
50 else { | 63 else { |
64 // Bubble the relevant cacheability metadata whenever possible. | |
65 if (isset($context[CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY])) { | |
66 $context[CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY]->addCacheContexts(['url.site']); | |
67 } | |
51 $request = $this->requestStack->getCurrentRequest(); | 68 $request = $this->requestStack->getCurrentRequest(); |
52 $this->linkDomain = $request->getSchemeAndHttpHost() . $request->getBasePath(); | 69 return $request->getSchemeAndHttpHost() . $request->getBasePath(); |
53 } | 70 } |
54 } | 71 } |
55 return $this->linkDomain; | 72 return $this->linkDomain; |
56 } | 73 } |
57 | 74 |