Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
uw_fdsu_theme_resp
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_fdsu_theme_resp
Commits
b05fb1ce
Commit
b05fb1ce
authored
6 years ago
by
Eric Bremner
Browse files
Options
Downloads
Patches
Plain Diff
Fixing getting responsive image variables to any field
parent
a8b5913f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
uw_fdsu_theme_resp.theme
+20
-28
20 additions, 28 deletions
uw_fdsu_theme_resp.theme
with
20 additions
and
28 deletions
uw_fdsu_theme_resp.theme
+
20
−
28
View file @
b05fb1ce
...
@@ -167,22 +167,13 @@ function _uw_fdsu_theme_resp_get_field_value_from_paragraph($paragraph, $field)
...
@@ -167,22 +167,13 @@ function _uw_fdsu_theme_resp_get_field_value_from_paragraph($paragraph, $field)
* Set the variables required for a responsive image.
* Set the variables required for a responsive image.
*
*
* @param $variables
* @param $variables
* @param $field
_name
* @param $field
* @param $responsive_image_style
* @param $responsive_image_style
*/
*/
function
_uw_fdsu_theme_resp_add_responsive_image_variables
(
&
$variables
,
$field_name
,
$responsive_image_style
,
$use_separate_variable
=
FALSE
)
{
function
_uw_fdsu_theme_resp_add_responsive_image_variables
(
&
$variables
,
$field
,
$responsive_image_style
)
{
// Get the field entity from the paragraph.
$field
=
$variables
[
'paragraph'
]
->
get
(
$field_name
)
->
first
();
// Set the alt tag from the field entity.
$variables
[
'alt'
]
=
$field
->
get
(
'alt'
)
->
getValue
();
// Set the file entity based on the field name.
$file
=
$field
->
entity
;
// If there is a file present, set responsive image variables.
// If there is a file present, set responsive image variables.
if
(
$file
)
{
if
(
$file
=
$field
->
entity
)
{
// Set uri and image style id.
// Set uri and image style id.
$variables
[
'uri'
]
=
$file
->
getFileUri
();
$variables
[
'uri'
]
=
$file
->
getFileUri
();
...
@@ -193,30 +184,31 @@ function _uw_fdsu_theme_resp_add_responsive_image_variables(&$variables, $field_
...
@@ -193,30 +184,31 @@ function _uw_fdsu_theme_resp_add_responsive_image_variables(&$variables, $field_
// for the responsive image style.
// for the responsive image style.
template_preprocess_responsive_image
(
$variables
);
template_preprocess_responsive_image
(
$variables
);
// Set the old_sources to the sources in variables.
// Start with clean arrays.
unset
(
$old_sources
);
unset
(
$new_sources
);
// Set old_sources to the ones set in the template preprocess.
$old_sources
=
$variables
[
'sources'
];
$old_sources
=
$variables
[
'sources'
];
//
Unset the sources variable
.
//
Step through each source and get string values
.
unset
(
$variables
[
'
source
s'
]);
foreach
(
$old_sources
as
$
source
)
{
// Step through each source and only get value.
// Set new_sources to the string values.
// This is need so that a render doesn't happen
$new_sources
[]
=
array
(
// and HTML escapes are put in place.
foreach
(
$old_sources
as
$source
)
{
$sources
[]
=
array
(
'srcset'
=>
$source
[
'srcset'
]
->
value
(),
'srcset'
=>
$source
[
'srcset'
]
->
value
(),
'media'
=>
$source
[
'media'
]
->
value
(),
'media'
=>
$source
[
'media'
]
->
value
(),
'type'
=>
$source
[
'type'
]
->
value
(),
'type'
=>
$source
[
'type'
]
->
value
(),
);
);
}
}
//
If not to set sources in variables, return sources
.
//
Set the alt tag for the picture
.
// Otherwise set the sources in variables.
$new_sources
[
'alt'
]
=
$field
->
get
(
'alt'
)
->
getValue
();
if
(
$use_separate_variable
)
{
return
$
sources
;
// Unset the old
sources
.
}
unset
(
$variables
[
'sources'
]);
else
{
$variables
[
'sources'
]
=
$
sources
;
// Return the new
sources
.
}
return
$new_sources
;
}
}
}
}
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