Skip to content
Snippets Groups Projects
Commit a0d5bc00 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2424697 by jedihe, yched: ResponsiveImageFormatter throws an exception on node preview

parent 097d6d35
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -16,7 +16,6 @@
use Drupal\Core\Url;
use Drupal\image\Plugin\Field\FieldFormatter\ImageFormatterBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\responsive_image\Entity\ResponsiveImageStyle;
use Drupal\image\Entity\ImageStyle;
/**
......@@ -179,7 +178,10 @@ public function viewElements(FieldItemListInterface $items) {
$url = NULL;
// Check if the formatter involves a link.
if ($this->getSetting('image_link') == 'content') {
$url = $items->getEntity()->urlInfo();
$entity = $items->getEntity();
if (!$entity->isNew()) {
$url = $entity->urlInfo();
}
}
elseif ($this->getSetting('image_link') == 'file') {
$link_file = TRUE;
......
......@@ -368,6 +368,25 @@ private function assertResponsiveImageFieldFormattersLink($link_type) {
$this->createImageField($field_name, 'article', array('uri_scheme' => 'public'));
// Create a new node with an image attached.
$test_image = current($this->drupalGetTestFiles('image'));
// Test the image linked to file formatter.
$display_options = array(
'type' => 'responsive_image',
'settings' => array(
'image_link' => $link_type,
'responsive_image_style' => 'style_one',
'fallback_image_style' => 'large',
),
);
entity_get_display('node', 'article', 'default')
->setComponent($field_name, $display_options)
->save();
// Ensure that preview works.
$this->previewNodeImage($test_image, $field_name, 'article');
// Look for a picture tag in the preview output
$this->assertPattern('/picture/');
$nid = $this->uploadNodeImage($test_image, $field_name, 'article');
$this->container->get('entity.manager')->getStorage('node')->resetCache(array($nid));
$node = Node::load($nid);
......
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