Issue #2424697 by jedihe, yched: ResponsiveImageFormatter throws an exception on node preview
parent
097d6d3554
commit
a0d5bc0097
|
@ -16,7 +16,6 @@ use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
|||
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 @@ class ResponsiveImageFormatter extends ImageFormatterBase implements ContainerFa
|
|||
$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 @@ class ResponsiveImageFieldDisplayTest extends ImageFieldTestBase {
|
|||
$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);
|
||||
|
|
Loading…
Reference in New Issue