diff --git a/core/modules/picture/lib/Drupal/picture/Plugin/Field/FieldFormatter/PictureFormatter.php b/core/modules/picture/lib/Drupal/picture/Plugin/Field/FieldFormatter/PictureFormatter.php
index eb1864d..3b86835 100644
--- a/core/modules/picture/lib/Drupal/picture/Plugin/Field/FieldFormatter/PictureFormatter.php
+++ b/core/modules/picture/lib/Drupal/picture/Plugin/Field/FieldFormatter/PictureFormatter.php
@@ -115,17 +115,10 @@ public function settingsSummary() {
public function viewElements(FieldItemListInterface $items) {
$elements = array();
// Check if the formatter involves a link.
- if ($this->getSetting('image_link') == 'content') {
- $uri = $items->getEntity()->urlInfo();
- // @todo Remove when theme_picture_formatter() has support for route name.
- $uri['path'] = $items->getEntity()->getSystemPath();
- }
- elseif ($this->getSetting('image_link') == 'file') {
- $link_file = TRUE;
- }
$breakpoint_styles = array();
- $fallback_image_style = '';
+ $image_styles = array_keys(image_style_options(FALSE));
+ $fallback_image_style = reset($image_styles);
$picture_mapping = entity_load('picture_mapping', $this->getSetting('picture_mapping'));
if ($picture_mapping) {
@@ -163,24 +156,54 @@ public function viewElements(FieldItemListInterface $items) {
}
foreach ($items as $delta => $item) {
- if (isset($link_file)) {
- $uri = array(
- 'path' => file_create_url($item->entity->getFileUri()),
- 'options' => array(),
- );
+ $item = $item->getValue(TRUE);
+ if (!isset($item['uri']) && isset($item['entity'])) {
+ $item['uri'] = $item['entity']->getFileUri();
}
- $elements[$delta] = array(
- '#theme' => 'picture_formatter',
+ if (isset($item['title']) && drupal_strlen($item['title']) == 0) {
+ unset($item['title']);
+ }
+ $picture = array(
+ '#theme' => 'picture',
+ '#style_name' => $fallback_image_style,
+ '#uri' => $item['uri'],
+ '#width' => $item['width'],
+ '#height' => $item['height'],
+ '#breakpoints' => $breakpoint_styles,
+ '#alt' => isset($item['alt']) || array_key_exists('alt', $item) ? $item['alt'] : NULL,
+ '#title' => isset($item['title']) ? $item['title'] : NULL,
+ '#attributes' => isset($item['attributes']) ? $item['attributes'] : NULL,
'#attached' => array('library' => array(
array('picture', 'picturefill'),
)),
- '#item' => $item,
- '#image_style' => $fallback_image_style,
- '#breakpoints' => $breakpoint_styles,
- '#path' => isset($uri) ? $uri : '',
);
+
+ // Check if the formatter involves a link.
+ if ($this->getSetting('image_link') == 'content') {
+ $uri = $entity->uri();
+ }
+ elseif ($this->getSetting('image_link') == 'file') {
+ $uri = array(
+ 'path' => file_create_url($item['uri']),
+ 'options' => array(),
+ );
+ }
+ if (isset($uri)) {
+ $elements[$delta] = array(
+ '#type' => 'link',
+ '#href' => $uri['path'],
+ '#title' => $picture,
+ '#options' => array(
+ 'html' => TRUE,
+ 'attributes' => isset($uri['attributes']) ? $uri['attributes'] : array(),
+ ),
+ );
+ }
+ else {
+ $elements[$delta] = $picture;
+ }
}
return $elements;
}
-}
+}
\ No newline at end of file
diff --git a/core/modules/picture/lib/Drupal/picture/Tests/PictureFieldDisplayTest.php b/core/modules/picture/lib/Drupal/picture/Tests/PictureFieldDisplayTest.php
index 7c11a6f..388e46a 100644
--- a/core/modules/picture/lib/Drupal/picture/Tests/PictureFieldDisplayTest.php
+++ b/core/modules/picture/lib/Drupal/picture/Tests/PictureFieldDisplayTest.php
@@ -199,14 +199,13 @@ public function _testPictureFieldFormatters($scheme) {
);
$default_output = '';
$this->drupalGet('node/' . $nid);
- $this->assertRaw($default_output, 'Image style thumbnail formatter displaying correctly on full node view.');
+ $this->assertRaw($default_output, 'Fallback image style (large) printed correctly on full node view.');
if ($scheme == 'private') {
// Log out and try to access the file.
$this->drupalLogout();
$this->drupalGet($large_style->buildUrl($image_uri));
- $this->assertResponse('403', 'Access denied to image style thumbnail as anonymous user.');
+ $this->assertResponse('403', 'Access denied to image style (large) as anonymous user.');
}
}
-
}
diff --git a/core/modules/picture/lib/Drupal/picture/Tests/PictureThemeFunctionsTest.php b/core/modules/picture/lib/Drupal/picture/Tests/PictureThemeFunctionsTest.php
new file mode 100644
index 0000000..201a6e6
--- /dev/null
+++ b/core/modules/picture/lib/Drupal/picture/Tests/PictureThemeFunctionsTest.php
@@ -0,0 +1,113 @@
+ 'Picture theme functions',
+ 'description' => 'Tests the picture theme functions.',
+ 'group' => 'Picture',
+ );
+ }
+
+ /**
+ * Tests usage of the template_preprocess_picture() function.
+ */
+ function testPictureTheme() {
+ // Create an image.
+ $files = $this->drupalGetTestFiles('image');
+ $file = reset($files);
+ $original_uri = file_unmanaged_copy($file->uri, 'public://', FILE_EXISTS_RENAME);
+
+ // Create a style.
+ $style = entity_create('image_style', array('name' => 'test', 'label' => 'Test'));
+ $style->save();
+ $url = $style->buildUrl($original_uri);
+
+ // Test using template_preprocess_picture() with a NULL value for the alt option.
+ $element = array(
+ '#theme' => 'picture',
+ '#uri' => $original_uri,
+ '#alt' => NULL,
+ '#style_name' => 'test',
+ );
+ $rendered_element = render($element);
+ $this->assertTrue(strpos($rendered_element, '