diff --git a/core/modules/rest/rest.install b/core/modules/rest/rest.install deleted file mode 100644 index b82b79e..0000000 --- a/core/modules/rest/rest.install +++ /dev/null @@ -1,17 +0,0 @@ -set('link_domain', Url::fromRoute('', [], ['absolute' => TRUE])->toString()) - ->save(); -} diff --git a/core/modules/rest/src/LinkManager/LinkManagerBase.php b/core/modules/rest/src/LinkManager/LinkManagerBase.php index 8f93de2..c40050d 100644 --- a/core/modules/rest/src/LinkManager/LinkManagerBase.php +++ b/core/modules/rest/src/LinkManager/LinkManagerBase.php @@ -6,6 +6,7 @@ */ namespace Drupal\rest\LinkManager; +use Drupal\Core\Url; /** * Defines an abstract base-class for REST link manager objects. @@ -26,4 +27,18 @@ public function setLinkDomain($domain) { $this->linkDomain = rtrim($domain, '/'); } + /** + * Gets the link domain. + * + * @return string + * The link domain. + */ + protected function getLinkDomain() { + if (empty($this->linkDomain)) { + $domain = Url::fromRoute('', [], ['absolute' => TRUE])->toString(); + $this->linkDomain = rtrim($domain, '/'); + } + return $this->linkDomain; + } + } diff --git a/core/modules/rest/src/LinkManager/RelationLinkManager.php b/core/modules/rest/src/LinkManager/RelationLinkManager.php index e44e988..301b459 100644 --- a/core/modules/rest/src/LinkManager/RelationLinkManager.php +++ b/core/modules/rest/src/LinkManager/RelationLinkManager.php @@ -13,7 +13,6 @@ use Drupal\Core\Entity\ContentEntityTypeInterface; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\Url; class RelationLinkManager extends LinkManagerBase implements RelationLinkManagerInterface { @@ -52,9 +51,6 @@ public function __construct(CacheBackendInterface $cache, EntityManagerInterface $this->cache = $cache; $this->entityManager = $entity_manager; $domain = $config_factory->get('rest.settings')->get('link_domain'); - if (empty($domain)) { - $domain = Url::fromRoute('', [], ['absolute' => TRUE])->toString(); - } $this->linkDomain = rtrim($domain, '/'); $this->moduleHandler = $module_handler; } @@ -63,7 +59,7 @@ public function __construct(CacheBackendInterface $cache, EntityManagerInterface * {@inheritdoc} */ public function getRelationUri($entity_type, $bundle, $field_name, $context = array()) { - $uri = $this->linkDomain . "/rest/relation/$entity_type/$bundle/$field_name"; + $uri = $this->getLinkDomain() . "/rest/relation/$entity_type/$bundle/$field_name"; $this->moduleHandler->alter('rest_relation_uri', $uri, $context); return $uri; } diff --git a/core/modules/rest/src/LinkManager/TypeLinkManager.php b/core/modules/rest/src/LinkManager/TypeLinkManager.php index 996b4a4..5f919ed 100644 --- a/core/modules/rest/src/LinkManager/TypeLinkManager.php +++ b/core/modules/rest/src/LinkManager/TypeLinkManager.php @@ -11,7 +11,6 @@ use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\Url; class TypeLinkManager extends LinkManagerBase implements TypeLinkManagerInterface { @@ -42,9 +41,6 @@ class TypeLinkManager extends LinkManagerBase implements TypeLinkManagerInterfac public function __construct(CacheBackendInterface $cache, ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config_factory) { $this->cache = $cache; $domain = $config_factory->get('rest.settings')->get('link_domain'); - if (empty($domain)) { - $domain = Url::fromRoute('', [], ['absolute' => TRUE])->toString(); - } $this->linkDomain = rtrim($domain, '/'); $this->moduleHandler = $module_handler; } @@ -63,7 +59,7 @@ public function __construct(CacheBackendInterface $cache, ModuleHandlerInterface * The URI that identifies this bundle. */ public function getTypeUri($entity_type, $bundle, $context = array()) { - $uri = $this->linkDomain . "/rest/type/$entity_type/$bundle"; + $uri = $this->getLinkDomain() . "/rest/type/$entity_type/$bundle"; $this->moduleHandler->alter('rest_type_uri', $uri, $context); return $uri; } @@ -130,4 +126,5 @@ protected function writeCache($context = array()) { // and only clear it when entity_info is cleared. $this->cache->set('rest:links:types', $data, Cache::PERMANENT, array('entity_types')); } + }