Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rift
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
rift
Commits
4da834d0
Commit
4da834d0
authored
3 months ago
by
Shibin Das
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3484013
: Image tag is not outputting height and width
parent
cb1e424b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Html/ImgElement.php
+4
-4
4 additions, 4 deletions
src/Html/ImgElement.php
src/Html/SourceElement.php
+69
-0
69 additions, 0 deletions
src/Html/SourceElement.php
src/RiftPicture.php
+18
-2
18 additions, 2 deletions
src/RiftPicture.php
with
91 additions
and
6 deletions
src/Html/ImgElement.php
+
4
−
4
View file @
4da834d0
...
...
@@ -215,10 +215,10 @@ class ImgElement extends ElementBase {
/**
* Getter for Width.
*
* @return int
* @return int
|null
* return Width.
*/
public
function
getWidth
():
int
{
public
function
getWidth
():
?
int
{
return
$this
->
width
;
}
...
...
@@ -239,10 +239,10 @@ class ImgElement extends ElementBase {
/**
* Getter for Height.
*
* @return int
* @return int
|null
* return Height.
*/
public
function
getHeight
():
int
{
public
function
getHeight
():
?
int
{
return
$this
->
height
;
}
...
...
This diff is collapsed.
Click to expand it.
src/Html/SourceElement.php
+
69
−
0
View file @
4da834d0
...
...
@@ -44,6 +44,20 @@ class SourceElement extends ElementBase {
*/
protected
array
$srcset
=
[];
/**
* The 'width' attribute.
*
* @var int|null
*/
protected
?int
$width
=
NULL
;
/**
* The 'height' attribute.
*
* @var int|null
*/
protected
?int
$height
=
NULL
;
/**
* Generates Drupal Render array for printing the Html Element.
*/
...
...
@@ -63,6 +77,12 @@ class SourceElement extends ElementBase {
*/
public
function
getAttribute
():
Attribute
{
$attribute
=
parent
::
getAttribute
();
if
(
!
empty
(
$this
->
width
))
{
$attribute
->
setAttribute
(
'width'
,
strval
(
$this
->
width
));
}
if
(
!
empty
(
$this
->
height
))
{
$attribute
->
setAttribute
(
'height'
,
strval
(
$this
->
height
));
}
if
(
!
empty
(
$this
->
src
))
{
$attribute
->
setAttribute
(
'src'
,
$this
->
src
);
}
...
...
@@ -216,4 +236,53 @@ class SourceElement extends ElementBase {
return
'source'
;
}
/**
* Getter for Width.
*
* @return int|null
* return Width.
*/
public
function
getWidth
():
?int
{
return
$this
->
width
;
}
/**
* Setter for Width.
*
* @param int $width
* Width value.
*
* @return SourceElement
* Self Reference.
*/
public
function
setWidth
(
int
$width
):
SourceElement
{
$this
->
width
=
$width
;
return
$this
;
}
/**
* Getter for Height.
*
* @return int|null
* return Height.
*/
public
function
getHeight
():
?int
{
return
$this
->
height
;
}
/**
* Setter for Height.
*
* @param int $height
* Height value.
*
* @return SourceElement
* Self Reference.
*/
public
function
setHeight
(
int
$height
):
SourceElement
{
$this
->
height
=
$height
;
return
$this
;
}
}
This diff is collapsed.
Click to expand it.
src/RiftPicture.php
+
18
−
2
View file @
4da834d0
...
...
@@ -5,6 +5,7 @@ namespace Drupal\rift;
use
Drupal\Core\Config\ConfigFactoryInterface
;
use
Drupal\Core\Render\Element
;
use
Drupal\Core\Render\RendererInterface
;
use
Drupal\Core\Template\Attribute
;
use
Drupal\media\MediaInterface
;
use
Drupal\rift\DTO\PictureConfig
;
use
Drupal\rift\DTO\SourceTransformConfig
;
...
...
@@ -255,7 +256,9 @@ class RiftPicture {
$img_element
->
setSrc
(
$url
)
->
setAlt
(
$image_source
->
getAlt
())
->
setTitle
(
$image_source
->
getTitle
());
->
setTitle
(
$image_source
->
getTitle
())
->
setHeight
(
$image_source
->
getHeight
())
->
setWidth
(
$image_source
->
getWidth
());
$picture_element
->
setImg
(
$img_element
);
$picture_element
->
setAttribute
(
$this
->
pictureConfig
->
attribute
);
...
...
@@ -320,7 +323,7 @@ class RiftPicture {
$url
=
$this
->
generateImageUrlFromStyles
(
$source
[
'styles'
],
$uri
);
$srcset_item
=
new
SrcSetItem
();
$srcset_item
->
setImg
(
$url
);
//
Red Flag, why is multiplier being injected into width?
//
Unlike traditional width, the width in srcset item is the multiplier.
$srcset_item
->
setWidth
(
$source
[
'multiplier'
]);
$srcset_items
[]
=
$srcset_item
;
// We set the type to the last one in the source.
...
...
@@ -328,6 +331,19 @@ class RiftPicture {
if
(
$source
[
'type'
])
{
$source_element
->
setType
(
$source
[
'type'
]);
}
if
(
!
$source_element
->
getHeight
())
{
if
(
$width
=
$source
[
'source_transform_config'
]
->
width
)
{
[
$arw
,
$arh
]
=
explode
(
'x'
,
$source
[
'source_transform_config'
]
->
aspectRatioStyle
);
if
(
$arh
>
0
)
{
$aspect_ratio
=
intval
(
$arw
)
/
intval
(
$arh
);
$height
=
intval
(
$width
/
$aspect_ratio
);
if
(
$height
)
{
$source_element
->
setWidth
(
$width
);
$source_element
->
setHeight
(
$height
);
}
}
}
}
}
$sizes_item
=
new
SizesItem
();
$sizes_item
->
setMediaQuery
(
$config
[
'media'
]);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment