Skip to content
Snippets Groups Projects
Verified Commit 3e8c2b34 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #2829990 by Krzysztof Domański, idebr, lamp5: Image formatter does not...

Issue #2829990 by Krzysztof Domański, idebr, lamp5: Image formatter does not support URL/Link options
parent de56b259
No related branches found
No related tags found
No related merge requests found
......@@ -14,7 +14,7 @@
*/
#}
{% if url %}
<a href="{{ url }}">{{ image }}</a>
{{ link(image, url) }}
{% else %}
{{ image }}
{% endif %}
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\image\Kernel;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Url;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -173,6 +174,31 @@ public function testImageFormatterSvg() {
$this->assertFalse(strpos($build[$this->fieldName][1]['#markup'], 'height'));
}
/**
* Tests Image Formatter URL options handling.
*/
public function testImageFormatterUrlOptions() {
$this->display->setComponent($this->fieldName, ['settings' => ['image_link' => 'content']]);
// Create a test entity with the image field set.
$entity = EntityTest::create([
'name' => $this->randomMachineName(),
]);
$entity->{$this->fieldName}->generateSampleItems(2);
$entity->save();
// Generate the render array to verify URL options are as expected.
$build = $this->display->build($entity);
$this->assertInstanceOf(Url::class, $build[$this->fieldName][0]['#url']);
$build[$this->fieldName][0]['#url']->setOption('attributes', ['data-attributes-test' => 'test123']);
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = $this->container->get('renderer');
$output = $renderer->renderRoot($build[$this->fieldName][0]);
$this->assertContains('<a href="' . $entity->toUrl()->toString() . '" data-attributes-test="test123"', (string) $output);
}
/**
* Asserts that a renderable array has a set of cache tags.
*
......
......@@ -13,7 +13,7 @@
*/
#}
{% if url %}
<a href="{{ url }}">{{ image }}</a>
{{ link(image, url) }}
{% else %}
{{ image }}
{% endif %}
......@@ -12,7 +12,7 @@
*/
#}
{% if url %}
<a href="{{ url }}">{{ image }}</a>
{{ link(image, url) }}
{% else %}
{{ image }}
{% endif %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment