diff --git a/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php b/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php index 060bec8..ec73503 100644 --- a/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php +++ b/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php @@ -147,7 +147,7 @@ public function viewElements(FieldItemListInterface $items) { unset($item->_attributes); if (isset($link_style_file)) { - $style = image_style_load($image_link_setting); + $style = entity_load('image_style', $image_link_setting); $uri = array( 'path' => $style->buildUrl($image_uri), 'options' => array(), diff --git a/core/modules/image/src/Tests/ImageFieldDisplayTest.php b/core/modules/image/src/Tests/ImageFieldDisplayTest.php index 1e8fd61..9d556da 100644 --- a/core/modules/image/src/Tests/ImageFieldDisplayTest.php +++ b/core/modules/image/src/Tests/ImageFieldDisplayTest.php @@ -159,6 +159,32 @@ function _testImageFieldFormatters($scheme) { $this->drupalGet(entity_load('image_style', 'thumbnail')->buildUrl($image_uri)); $this->assertResponse('403', 'Access denied to image style thumbnail as anonymous user.'); } + + // Test if image_styles are linked correctly. + $display_options['settings']['image_link'] = 'thumbnail'; + $display_options['settings']['image_style'] = 'medium'; + + $display->setComponent($field_name, $display_options) + ->save(); + + if ($scheme == 'private') { + $this->drupalLogin($this->admin_user); + } + + $this->drupalGet('node/' . $nid); + $cache_tags = explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Tags')); + $this->assertTrue(in_array('image_style:medium', $cache_tags)); + + $elements = $this->xpath( + '//a[@href=:path]/img[@src=:url and @alt="" and @width=:width and @height=:height]', + array( + ':path' => entity_load('image_style', 'thumbnail')->buildUrl($image_uri), + ':url' => entity_load('image_style', 'medium')->buildUrl($image_uri), + ':width' => 40, + ':height' => 20, + ) + ); + $this->assertEqual(count($elements), 1, 'Image linked to image style formatter displaying correctly on full node view.'); } /**