Skip to content
Snippets Groups Projects
Commit 68c611fe authored by Shibin Das's avatar Shibin Das
Browse files

Issue #3495393: Document usage of Twig Filter to print RIFT view modes

parent 642a3243
No related branches found
No related tags found
No related merge requests found
......@@ -66,9 +66,9 @@ class Rift extends AbstractExtension {
* @param array $config
* Configuration for generating srcset.
* <code>
* content.field_common_image|repsonsive_image({
* sources: "120w 320w 320w 1024w 1024w",
* ratios: "1x1 16x9 1x1 1x1 1x1",
* content.field_common_image|rift_picture({
* sizes: "120w 320w 320w 1024w 1024w",
* aspect_ratios: "1x1 16x9 1x1 1x1 1x1",
* quality: {
* 1x: "80 80 80 80 80",
* 2x: "40 40 40 40 40",
......
......@@ -166,7 +166,7 @@ class RiftPicture {
* @param array $config
* Configuration for generating srcset.
* <code>
* content.field_common_image|repsonsive_image({
* content.field_common_image|rift_picture({
* sources: "120w 320w 320w 1024w 1024w",
* aspect_ratios: "1x1 16x9 1x1 1x1 1x1",
* quality: {
......@@ -215,7 +215,7 @@ class RiftPicture {
* @param array $config
* Configuration for generating srcset.
* <code>
* content.field_common_image|repsonsive_image({
* content.field_common_image|rift_picture({
* sources: "120w 320w 320w 1024w 1024w",
* aspect_ratios: "1x1 16x9 1x1 1x1 1x1",
* quality: {
......
......@@ -348,6 +348,44 @@ class RiftPictureTest extends ExistingSiteBase {
}
}
/**
* Test "rift_picture" Twig Filter.
*/
public function testResponsivePictureTwigFilter() {
$file = File::create([
'uri' => $this->getTestFiles('image')[0]->uri,
]);
$file->save();
$media = $this->createMedia([
'bundle' => 'image',
'field_media_image' => [
'target_id' => $file->id(),
'title' => 'dummy title',
'alt' => 'dummy alt',
],
]);
$this->markEntityForCleanup($file);
$this->markEntityForCleanup($media);
$elements = [
'#type' => 'inline_template',
'#template' => '{{ media|rift_picture({
sizes: "sm:100w",
aspect_ratios: "1x2",
url_generation_strategy: "placeholdit",
})
}}',
'#context' => [
'media' => $media,
]
];
/** @var \Drupal\Core\Render\Renderer $renderer */
$renderer = \Drupal::service('renderer');
$output = $renderer->renderInIsolation($elements);
$html = '<picture loading="lazy" preload=""><source width="100" height="200" type="image/webp" sizes="100w" srcset="https://place-hold.it/100x200?text=100w200h-webp-80 1x,https://place-hold.it/200x400?text=200w400h-webp-40 2x" /><source width="100" height="200" type="image/jpeg" sizes="100w" srcset="https://place-hold.it/100x200?text=100w200h-jpeg-80 1x,https://place-hold.it/200x400?text=200w400h-jpeg-40 2x" /><img src="https://place-hold.it/x?text=medium-80" alt="dummy alt" title="dummy title" width="40" height="20" /></picture>';
$this->assertEquals($html, $output);
}
/**
* Test responsive picture format support.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment