Commit 793d9a5f authored by webchick's avatar webchick

Issue #2483357 by googletorp, floydm, darol100, alexpott, paulmckibben: Fatal...

Issue #2483357 by googletorp, floydm, darol100, alexpott, paulmckibben: Fatal "Unsupported operand types" error when using responsive images in views
parent 41b6af54
......@@ -90,7 +90,10 @@ function template_preprocess_responsive_image_formatter(&$variables) {
$attributes['title'] = $item->title;
}
$attributes['alt'] = $item->alt;
$attributes += $variables['item_attributes'];
// Need to check that item_attributes has a value since it can be NULL.
if ($variables['item_attributes']) {
$attributes += $variables['item_attributes'];
}
if (($entity = $item->entity) && empty($item->uri)) {
$variables['responsive_image']['#uri'] = $entity->getFileUri();
}
......
......@@ -190,6 +190,19 @@ protected function doTestResponsiveImageFieldFormatters($scheme, $empty_styles =
);
$default_output = str_replace("\n", NULL, $renderer->renderRoot($image));
$this->assertRaw($default_output, 'Default formatter displaying correctly on full node view.');
// Test theme function for responsive image, but using the test formatter.
$display_options = array(
'type' => 'responsive_image_test',
'settings' => array(
'image_link' => 'file',
'responsive_image_style' => 'style_one',
),
);
$display = entity_get_display('node', 'article', 'default');
$display->setComponent($field_name, $display_options)
->save();
$this->drupalGet('node/' . $nid);
// Use the responsive image formatter linked to file formatter.
$display_options = array(
......
# Schema for the configuration files of the Responsive image test theme module.
field.formatter.settings.responsive_image_test:
type: mapping
label: 'Responsive image list format settings'
mapping:
responsive_image_style:
type: string
label: 'Responsive image style'
image_link:
type: string
label: 'Link image to'
<?php
/**
* @file
* Contains \Drupal\responsive_image_test_module\Plugin\Field\FieldFormatter\ResponsiveImageTestFormatter.
*/
namespace Drupal\responsive_image_test_module\Plugin\Field\FieldFormatter;
use Drupal\responsive_image\Plugin\Field\FieldFormatter\ResponsiveImageFormatter;
use Drupal\Core\Field\FieldItemListInterface;
/**
* Plugin to test responsive image formatter.
*
* @FieldFormatter(
* id = "responsive_image_test",
* label = @Translation("Responsive image test"),
* field_types = {
* "image",
* }
* )
*/
class ResponsiveImageTestFormatter extends ResponsiveImageFormatter {
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items) {
$elements = parent::viewElements($items);
// Unset #item_attributes to test that the theme function can handle that.
foreach ($elements as &$element) {
if (isset($element['#item_attributes'])) {
unset($element['#item_attributes']);
}
}
return $elements;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment