Skip to content

Commit

Permalink
Merge branch 'release2.11.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
RicLeP committed Mar 30, 2022
2 parents 8fe90d0 + da4a12e commit b33ce88
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/Fields/Image.php
Expand Up @@ -168,7 +168,7 @@ public function picture($alt = '', $default = null, $attributes = [], $view = 'l
* @return string
*/
public function srcset($alt = '', $default = null, $attributes = [], $view = 'laravel-storyblok::srcset') {
return $this->picture($alt, $default, $attributes, 'laravel-storyblok::srcset', true);
return $this->picture($alt, $default, $attributes, 'laravel-storyblok::srcset');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/resources/views/srcset.blade.php
@@ -1,2 +1,2 @@

<img srcset="@foreach($transformations as $key => $transformation) {{ $transformation['src'] }} {{ $transformation['src']->width() }}w, @endforeach" sizes="@foreach($transformations as $key => $transformation) @if ($default !== $key) @if (!$loop->last) {{ $transformation['media'] }} @endif {{ $transformation['src']->width() }}px, @endif @endforeach" src="{{ $imgSrc }}" alt="{{ $alt }}" @foreach ($attributes as $attribute => $value) {{$attribute}}="{{$value}}" @endforeach>
<img srcset="@foreach($transformations as $key => $transformation) {{ $transformation['src'] }} {{ $transformation['src']->width() }}w, @endforeach" sizes="@foreach($transformations as $key => $transformation) @if ($default !== $key) {{ $transformation['media'] }} {{ $transformation['src']->width() }}px, @endif @endforeach" src="{{ $imgSrc }}" alt="{{ $alt }}" @foreach ($attributes as $attribute => $value) {{$attribute}}="{{$value}}" @endforeach>
18 changes: 4 additions & 14 deletions tests/FieldTest.php
Expand Up @@ -306,8 +306,8 @@ public function can_get_create_picture_elements()

$this->assertEquals(<<<'PICTURE'
<picture>
<source srcset="https://a.storyblok.com/f/87028/960x1280/31a1d8dc75/bottle.jpg/m/100x120/filters:format(webp)" type="image/webp" media="(min-width: 600px)">
<source srcset="https://a.storyblok.com/f/87028/960x1280/31a1d8dc75/bottle.jpg/m/500x400" type="image/jpeg" media="(min-width: 1200px)">
<source srcset="https://a.storyblok.com/f/87028/960x1280/31a1d8dc75/bottle.jpg/m/100x120/filters:format(webp)" type="image/webp" media="(min-width: 600px)">
<img src="https://a.storyblok.com/f/87028/960x1280/31a1d8dc75/bottle.jpg" alt="Some alt text with &quot;" >
</picture>
Expand Down Expand Up @@ -386,8 +386,8 @@ public function can_get_create_picture_element_with_custom_domains()

$this->assertEquals(<<<'PICTURE'
<picture>
<source srcset="https://custom.imageservice.domain/f/87028/960x1280/31a1d8dc75/bottle.jpg/m/100x120/filters:format(webp)" type="image/webp" media="(min-width: 600px)">
<source srcset="https://custom.imageservice.domain/f/87028/960x1280/31a1d8dc75/bottle.jpg/m/500x400" type="image/jpeg" media="(min-width: 1200px)">
<source srcset="https://custom.imageservice.domain/f/87028/960x1280/31a1d8dc75/bottle.jpg/m/100x120/filters:format(webp)" type="image/webp" media="(min-width: 600px)">
<img src="https://custom.asset.domain/f/87028/960x1280/31a1d8dc75/bottle.jpg" alt="Some alt text with &quot;" >
</picture>
Expand All @@ -402,12 +402,7 @@ public function can_create_img_srcset()
$field = new HeroImage($this->getFieldContents('hero'), null);

$this->assertEquals(<<<'SRCSET'
<img srcset=" https://a.storyblok.com/f/87028/960x1280/31a1d8dc75/bottle.jpg/m/500x400 500w, https://a.storyblok.com/f/87028/960x1280/31a1d8dc75/bottle.jpg/m/100x120/filters:format(webp) 100w, " sizes=" (min-width: 1200px) 500px, 100px, " src="https://a.storyblok.com/f/87028/960x1280/31a1d8dc75/bottle.jpg" alt="Some alt text with &quot;" >
SRCSET
, str_replace("\t", '', $field->srcset('Some alt text with "')));

$this->assertEquals(<<<'SRCSET'
<img srcset=" https://a.storyblok.com/f/87028/960x1280/31a1d8dc75/bottle.jpg/m/500x400 500w, https://a.storyblok.com/f/87028/960x1280/31a1d8dc75/bottle.jpg/m/100x120/filters:format(webp) 100w, " sizes=" (min-width: 1200px) 500px, 100px, " src="https://a.storyblok.com/f/87028/960x1280/31a1d8dc75/bottle.jpg" alt="Some alt text with &quot;" >
<img srcset=" https://a.storyblok.com/f/87028/960x1280/31a1d8dc75/bottle.jpg/m/500x400 500w, https://a.storyblok.com/f/87028/960x1280/31a1d8dc75/bottle.jpg/m/100x120/filters:format(webp) 100w, " sizes=" (min-width: 1200px) 500px, (min-width: 600px) 100px, " src="https://a.storyblok.com/f/87028/960x1280/31a1d8dc75/bottle.jpg" alt="Some alt text with &quot;" >
SRCSET
, str_replace("\t", '', $field->srcset('Some alt text with "')));
}
Expand All @@ -421,12 +416,7 @@ public function can_create_img_srcset_with_custom_domains()
$field = new HeroImage($this->getFieldContents('hero'), null);

$this->assertEquals(<<<'SRCSET'
<img srcset=" https://custom.imageservice.domain/f/87028/960x1280/31a1d8dc75/bottle.jpg/m/500x400 500w, https://custom.imageservice.domain/f/87028/960x1280/31a1d8dc75/bottle.jpg/m/100x120/filters:format(webp) 100w, " sizes=" (min-width: 1200px) 500px, 100px, " src="https://custom.asset.domain/f/87028/960x1280/31a1d8dc75/bottle.jpg" alt="Some alt text with &quot;" >
SRCSET
, str_replace("\t", '', $field->srcset('Some alt text with "')));

$this->assertEquals(<<<'SRCSET'
<img srcset=" https://custom.imageservice.domain/f/87028/960x1280/31a1d8dc75/bottle.jpg/m/500x400 500w, https://custom.imageservice.domain/f/87028/960x1280/31a1d8dc75/bottle.jpg/m/100x120/filters:format(webp) 100w, " sizes=" (min-width: 1200px) 500px, 100px, " src="https://custom.asset.domain/f/87028/960x1280/31a1d8dc75/bottle.jpg" alt="Some alt text with &quot;" >
<img srcset=" https://custom.imageservice.domain/f/87028/960x1280/31a1d8dc75/bottle.jpg/m/500x400 500w, https://custom.imageservice.domain/f/87028/960x1280/31a1d8dc75/bottle.jpg/m/100x120/filters:format(webp) 100w, " sizes=" (min-width: 1200px) 500px, (min-width: 600px) 100px, " src="https://custom.asset.domain/f/87028/960x1280/31a1d8dc75/bottle.jpg" alt="Some alt text with &quot;" >
SRCSET
, str_replace("\t", '', $field->srcset('Some alt text with "')));
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Fixtures/Fields/HeroImage.php
Expand Up @@ -11,14 +11,14 @@ class HeroImage extends Image

public function transformations() {
$this->transformations = [
'mobile' => [
'src' => $this->transform()->resize(100, 120)->format('webp'),
'media' => '(min-width: 600px)',
],
'desktop' => [
'src' => $this->transform()->resize(500, 400),
'media' => '(min-width: 1200px)',
],
'mobile' => [
'src' => $this->transform()->resize(100, 120)->format('webp'),
'media' => '(min-width: 600px)',
],
];
}
}

0 comments on commit b33ce88

Please sign in to comment.