.../Field/FieldFormatter/BaseFieldFileFormatterBase.php | 14 +-------------
.../src/Plugin/Field/FieldFormatter/FileUriFormatter.php | 5 +----
core/modules/file/src/Plugin/views/field/File.php | 8 +-------
.../src/Plugin/Field/FieldFormatter/ImageFormatter.php | 10 +---------
.../image/tests/src/Functional/ImageFieldDisplayTest.php | 4 +---
5 files changed, 5 insertions(+), 36 deletions(-)
diff --git a/core/modules/file/src/Plugin/Field/FieldFormatter/BaseFieldFileFormatterBase.php b/core/modules/file/src/Plugin/Field/FieldFormatter/BaseFieldFileFormatterBase.php
index b54b17b..a1aedda 100644
--- a/core/modules/file/src/Plugin/Field/FieldFormatter/BaseFieldFileFormatterBase.php
+++ b/core/modules/file/src/Plugin/Field/FieldFormatter/BaseFieldFileFormatterBase.php
@@ -47,9 +47,7 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
$url = NULL;
// Add support to link to the entity itself.
if ($this->getSetting('link_to_file')) {
- // @todo Wrap in file_url_transform_relative(). This is currently
- // impossible. See below.
- $url = file_create_url($items->getEntity()->uri->value);
+ $url = file_url_transform_relative(file_create_url($items->getEntity()->uri->value));
}
foreach ($items as $delta => $item) {
@@ -60,16 +58,6 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
'#type' => 'link',
'#title' => $view_value,
'#url' => Url::fromUri($url),
- // @todo Remove the 'url.site' cache context by using a relative file
- // URL (file_url_transform_relative()). This is currently impossible
- // because #type => link requires a Url object, and Url objects do not
- // support relative URLs: they require fully qualified URLs. Fix in
- // https://www.drupal.org/node/2646744.
- '#cache' => [
- 'contexts' => [
- 'url.site',
- ],
- ],
];
}
else {
diff --git a/core/modules/file/src/Plugin/Field/FieldFormatter/FileUriFormatter.php b/core/modules/file/src/Plugin/Field/FieldFormatter/FileUriFormatter.php
index 0facb7e..c4fc6e9 100644
--- a/core/modules/file/src/Plugin/Field/FieldFormatter/FileUriFormatter.php
+++ b/core/modules/file/src/Plugin/Field/FieldFormatter/FileUriFormatter.php
@@ -51,10 +51,7 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
protected function viewValue(FieldItemInterface $item) {
$value = $item->value;
if ($this->getSetting('file_download_path')) {
- // @todo Wrap in file_url_transform_relative(). This is currently
- // impossible. See BaseFieldFileFormatterBase::viewElements(). Fix in
- // https://www.drupal.org/node/2646744.
- $value = file_create_url($value);
+ $value = file_url_transform_relative(file_create_url($value));
}
return $value;
}
diff --git a/core/modules/file/src/Plugin/views/field/File.php b/core/modules/file/src/Plugin/views/field/File.php
index 57d8c60..c139b3e 100644
--- a/core/modules/file/src/Plugin/views/field/File.php
+++ b/core/modules/file/src/Plugin/views/field/File.php
@@ -64,13 +64,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
protected function renderLink($data, ResultRow $values) {
if (!empty($this->options['link_to_file']) && $data !== NULL && $data !== '') {
$this->options['alter']['make_link'] = TRUE;
- // @todo Wrap in file_url_transform_relative(). This is currently
- // impossible. As a work-around, we could add the 'url.site' cache context
- // to ensure different file URLs are generated for different sites in a
- // multisite setup, including HTTP and HTTPS versions of the same site.
- // But unfortunately it's impossible to bubble a cache context here.
- // Fix in https://www.drupal.org/node/2646744.
- $this->options['alter']['path'] = file_create_url($this->getValue($values, 'uri'));
+ $this->options['alter']['path'] = file_url_transform_relative(file_create_url($this->getValue($values, 'uri')));
}
return $data;
diff --git a/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php b/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php
index 77714d2..eab8c41 100644
--- a/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php
+++ b/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php
@@ -200,16 +200,9 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
}
foreach ($files as $delta => $file) {
- $cache_contexts = [];
if (isset($link_file)) {
$image_uri = $file->getFileUri();
- // @todo Wrap in file_url_transform_relative(). This is currently
- // impossible. As a work-around, we currently add the 'url.site' cache
- // context to ensure different file URLs are generated for different
- // sites in a multisite setup, including HTTP and HTTPS versions of the
- // same site. Fix in https://www.drupal.org/node/2646744.
- $url = Url::fromUri(file_create_url($image_uri));
- $cache_contexts[] = 'url.site';
+ $url = Url::fromUri(file_url_transform_relative(file_create_url($image_uri)));
}
$cache_tags = Cache::mergeTags($base_cache_tags, $file->getCacheTags());
@@ -227,7 +220,6 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
'#url' => $url,
'#cache' => [
'tags' => $cache_tags,
- 'contexts' => $cache_contexts,
],
];
}
diff --git a/core/modules/image/tests/src/Functional/ImageFieldDisplayTest.php b/core/modules/image/tests/src/Functional/ImageFieldDisplayTest.php
index 33e042e..14b6c2e 100644
--- a/core/modules/image/tests/src/Functional/ImageFieldDisplayTest.php
+++ b/core/modules/image/tests/src/Functional/ImageFieldDisplayTest.php
@@ -127,11 +127,9 @@ public function _testImageFieldFormatters($scheme) {
'#height' => 20,
'#alt' => $alt,
];
- $default_output = '' . $renderer->renderRoot($image) . '';
+ $default_output = '' . $renderer->renderRoot($image) . '';
$this->drupalGet('node/' . $nid);
$this->assertCacheTag($file->getCacheTags()[0]);
- // @todo Remove in https://www.drupal.org/node/2646744.
- $this->assertCacheContext('url.site');
$cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags');
$this->assertTrue(!preg_match('/ image_style\:/', $cache_tags_header), 'No image style cache tag found.');
$this->assertRaw($default_output, 'Image linked to file formatter displaying correctly on full node view.');