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
052603f8
Commit
052603f8
authored
7 years ago
by
Eric Bremner
Browse files
Options
Downloads
Patches
Plain Diff
ISTWCMS-2443: Adding preprocessing for responsive image styles in paragraphs
parent
364a28a3
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
+51
-1
51 additions, 1 deletion
uw_fdsu_theme_resp.theme
with
51 additions
and
1 deletion
uw_fdsu_theme_resp.theme
+
51
−
1
View file @
052603f8
...
...
@@ -4,7 +4,6 @@
* uw_fdsu_theme_resp.module
*/
use
Drupal\Core\Template\Attribute
;
/**
* Implements hook_preprocess_region().
...
...
@@ -26,3 +25,54 @@ function uw_fdsu_theme_resp_preprocess_region(&$variables) {
$variables
[
'attributes'
][
'class'
][]
=
'default'
;
}
}
/**
* Implements hook_preprocess_paragraph().
*
* Get the sources for responsive image.
*/
function
uw_fdsu_theme_resp_preprocess_paragraph
(
&
$variables
)
{
// Check that we are on a specific paragraph and
// set image variables accordingly.
switch
(
$variables
[
'paragraph'
]
->
getType
())
{
case
"uw_para_marketing_block"
:
// Set the responsive image variables.
_uw_fdsu_theme_resp_add_responsive_image_variables
(
$variables
,
'field_uw_marketing_image'
,
'uw_resp_is_marketing_item'
);
break
;
}
}
/**
* Helper function.
*
* Set the variables required for a responsive image.
*
* @param $variables
* @param $field_name
* @param $responsive_image_style
*/
function
_uw_fdsu_theme_resp_add_responsive_image_variables
(
&
$variables
,
$field_name
,
$responsive_image_style
)
{
// Get the field entity from the paragraph.
$field
=
$variables
[
'paragraph'
]
->
get
(
$field_name
)
->
first
();
// Set the file entity based on the field name.
$file
=
$field
->
entity
;
// If there is a file present, set responsive image variables.
if
(
$file
)
{
// Set uri and image style id.
$variables
[
'uri'
]
=
$file
->
getFileUri
();
$variables
[
'responsive_image_style_id'
]
=
$responsive_image_style
;
// Call template function from responsive image core module.
// It sets variables for srcset, media, type and img_element
// for the responsive image style.
template_preprocess_responsive_image
(
$variables
);
}
}
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