Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uw_cfg_common
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WCMS
uw_cfg_common
Commits
9874d11e
Commit
9874d11e
authored
3 years ago
by
Eric Bremner
Committed by
Igor Biki
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
ISTWCMS-5195: updating prepareResponsiveImage to ensure that entities are not null
parent
ca752792
No related branches found
No related tags found
1 merge request
!169
Feature/istwcms 5195 ebremner node theming
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Service/UWService.php
+28
-24
28 additions, 24 deletions
src/Service/UWService.php
with
28 additions
and
24 deletions
src/Service/UWService.php
+
28
−
24
View file @
9874d11e
...
@@ -81,31 +81,35 @@ class UWService implements UWServiceInterface {
...
@@ -81,31 +81,35 @@ class UWService implements UWServiceInterface {
*/
*/
public
function
prepareResponsiveImage
(
EntityInterface
$entity
,
string
$image_style
):
array
{
public
function
prepareResponsiveImage
(
EntityInterface
$entity
,
string
$image_style
):
array
{
// Load in the file object if we have one.
// Ensure that we can load an entity on the media.
if
(
$file
=
$entity
->
field_media_image
->
entity
)
{
if
(
isset
(
$entity
->
field_media_image
->
entity
))
{
// Need to set these variables so that responsive image function,
// Load in the file object if we have one.
// has all the necessary info to process the image style.
if
(
$file
=
$entity
->
field_media_image
->
entity
)
{
$variables
[
'uri'
]
=
$file
->
getFileUri
();
$variables
[
'responsive_image_style_id'
]
=
$image_style
;
// Need to set these variables so that responsive image function,
// has all the necessary info to process the image style.
// Set the alt for the image.
$variables
[
'uri'
]
=
$file
->
getFileUri
();
$variables
[
'alt'
]
=
$entity
->
field_media_image
->
alt
;
$variables
[
'responsive_image_style_id'
]
=
$image_style
;
// These is a function from the responsive image module that sets all
// Set the alt for the image.
// the variables for the sources of the responsive image.
$variables
[
'alt'
]
=
$entity
->
field_media_image
->
alt
;
template_preprocess_responsive_image
(
$variables
);
// These is a function from the responsive image module that sets all
// Step through each of the sources and setup our own sources array.
// the variables for the sources of the responsive image.
foreach
(
$variables
[
'sources'
]
as
$source
)
{
template_preprocess_responsive_image
(
$variables
);
$variables
[
'responsive_sources'
][]
=
[
'srcset'
=>
$source
->
storage
()[
'srcset'
]
->
value
(),
// Step through each of the sources and setup our own sources array.
'media'
=>
$source
->
storage
()[
'media'
]
->
value
(),
foreach
(
$variables
[
'sources'
]
as
$source
)
{
'type'
=>
$source
->
storage
()[
'type'
]
->
value
(),
$variables
[
'responsive_sources'
][]
=
[
];
'srcset'
=>
$source
->
storage
()[
'srcset'
]
->
value
(),
}
'media'
=>
$source
->
storage
()[
'media'
]
->
value
(),
'type'
=>
$source
->
storage
()[
'type'
]
->
value
(),
];
}
return
$variables
;
return
$variables
;
}
}
}
return
[];
return
[];
...
...
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