116c116
< index 0000000..494e6f4
---
> index 0000000..201a6e6
119c119
< @@ -0,0 +1,115 @@
---
> @@ -0,0 +1,113 @@
152c152
< + * Tests usage of the theme_picture() function.
---
> + * Tests usage of the template_preprocess_picture() function.
165,166c165
< + // Test using theme_picture() with a NULL value for the alt option.
< + $path = $this->randomName();
---
> + // Test using template_preprocess_picture() with a NULL value for the alt option.
174,175c173
< + $expected_result = '
';
< + $this->assertTrue(strpos($rendered_element, '') !== FALSE, 'picture element in theme_picture() correctly renders with a NULL value for the alt option.');
---
> + $this->assertTrue(strpos($rendered_element, '') !== FALSE, 'picture element in template_preprocess_picture() correctly renders with a NULL value for the alt option.');
177c175
< + // Test using theme_picture() without passing a value for the alt option.
---
> + // Test using template_preprocess_picture() without passing a value for the alt option.
181,182c179,180
< + $this->assertTrue(strpos($rendered_element, $expected_result) !== FALSE, 'img element in theme_picture() correctly renders the alt option.');
< + $this->assertTrue(strpos($rendered_element, '') !== FALSE, 'picture element in theme_picture() correctly renders the alt option.');
---
> + $this->assertTrue(strpos($rendered_element, $expected_result) !== FALSE, 'img element in template_preprocess_picture() correctly renders the alt option.');
> + $this->assertTrue(strpos($rendered_element, '') !== FALSE, 'picture1 element in template_preprocess_picture() correctly renders the alt option.');
211c209
< + );
---
> + );$expected_result = '
';
236c234
< index ae676c9..331c6d0 100644
---
> index f7aecac..0651831 100644
239c237
< @@ -118,94 +118,31 @@ function picture_theme() {
---
> @@ -94,94 +94,31 @@ function picture_theme() {
243c241,242
< - ),
---
> + 'template' => 'picture',
> ),
259,264c258,262
< + 'template' => 'picture',
< ),
< );
< }
<
< /**
---
> - ),
> - );
> -}
> -
> -/**
294c292
< - );
---
> );
315,317c313,315
< -}
< -
< -/**
---
> }
>
> /**
345c343
< @@ -218,124 +155,94 @@ function theme_picture($variables) {
---
> @@ -194,124 +131,94 @@ function theme_picture($variables) {
366a365,372
> +
> + if (!empty($variables['breakpoints'])) {
> + // Fallback image, output as source with media query.
> + $src_attributes = picture_get_image_dimensions($variables);
> + $src_attributes['src'] = entity_load('image_style', $variables['style_name'])->buildUrl($variables['uri']);
> + $variables['sources'][] = array(
> + 'attributes' => new Attribute($src_attributes),
> + );
379,399d384
< + if (!empty($variables['breakpoints'])) {
< + // Fallback image, output as source with media query.
< + $src_attributes = picture_get_image_dimensions($variables);
< + $src_attributes['src'] = entity_load('image_style', $variables['style_name'])->buildUrl($variables['uri']);
< + $variables['sources'][] = array(
< + 'attributes' => new Attribute($src_attributes),
< + );
<
< - // Only one image, use src.
< - if (count($new_sources) == 1) {
< - $sources[] = array(
< - 'src' => entity_load('image_style', $new_sources[0]['style_name'])->buildUrl($new_sources[0]['uri']),
< - 'dimensions' => picture_get_image_dimensions($new_sources[0]),
< - 'media' => $breakpoint->mediaQuery,
< - );
< - }
< - else {
< - // Multiple images, use srcset.
< - $srcset = array();
< - foreach ($new_sources as $new_source) {
< - $srcset[] = entity_load('image_style', $new_source['style_name'])->buildUrl($new_source['uri']) . ' ' . $new_source['#multiplier'];
410c395,398
< }
---
> + }
>
> - // Only one image, use src.
> - if (count($new_sources) == 1) {
412c400
< - 'srcset' => implode(', ', $srcset),
---
> - 'src' => entity_load('image_style', $new_sources[0]['style_name'])->buildUrl($new_sources[0]['uri']),
417,427c405,409
< - }
< - }
<
< - if (!empty($sources)) {
< - $attributes = array();
< - foreach (array('alt', 'title') as $key) {
< - if (isset($variables[$key])) {
< - $attributes[$key] = $variables[$key];
< - }
< - }
< - $output[] = '';
---
> - else {
> - // Multiple images, use srcset.
> - $srcset = array();
> - foreach ($new_sources as $new_source) {
> - $srcset[] = entity_load('image_style', $new_source['style_name'])->buildUrl($new_source['uri']) . ' ' . $new_source['#multiplier'];
435c417,421
< + }
---
> }
> - $sources[] = array(
> - 'srcset' => implode(', ', $srcset),
> - 'dimensions' => picture_get_image_dimensions($new_sources[0]),
> - 'media' => $breakpoint->mediaQuery,
442,454c428
<
< - // Add source tags to the output.
< - foreach ($sources as $source) {
< - $picture_source = array(
< - '#theme' => 'picture_source',
< - '#src' => $source['src'],
< - '#dimensions' => $source['dimensions'],
< - );
< - if (isset($source['media'])) {
< - $picture_source['#media'] = $source['media'];
< - }
< - if (isset($source['srcset'])) {
< - $picture_source['#srcset'] = $source['srcset'];
---
> +
470c444
< + );
---
> );
472d445
< - $output[] = drupal_render($picture_source);
473a447,472
> - }
> -
> - if (!empty($sources)) {
> - $attributes = array();
> - foreach (array('alt', 'title') as $key) {
> - if (isset($variables[$key])) {
> - $attributes[$key] = $variables[$key];
> - }
> - }
> - $output[] = '';
> -
> - // Add source tags to the output.
> - foreach ($sources as $source) {
> - $picture_source = array(
> - '#theme' => 'picture_source',
> - '#src' => $source['src'],
> - '#dimensions' => $source['dimensions'],
> - );
> - if (isset($source['media'])) {
> - $picture_source['#media'] = $source['media'];
> - }
> - if (isset($source['srcset'])) {
> - $picture_source['#srcset'] = $source['srcset'];
> - }
> - $output[] = drupal_render($picture_source);
> - }
543c542
< @@ -358,7 +265,9 @@ function picture_get_image_dimensions($variables) {
---
> @@ -334,7 +241,9 @@ function picture_get_image_dimensions($variables) {