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
54904653
Commit
54904653
authored
3 years ago
by
Eric Bremner
Committed by
Martin Leblanc
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
ISTWCMS-5204: updating the display of images to only include those images stlyes used for an image
parent
2d9f7abc
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!180
ISTWCMS-5204: updating node theming to use a free flowing image
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
uw_cfg_common.module
+63
-0
63 additions, 0 deletions
uw_cfg_common.module
with
63 additions
and
0 deletions
uw_cfg_common.module
+
63
−
0
View file @
54904653
...
...
@@ -722,6 +722,69 @@ function uw_cfg_common_form_menu_link_content_menu_link_content_form_alter(array
unset
(
$form
[
'menu_parent'
][
'#options'
][
'main:uw_base_profile.front_page'
]);
}
/**
* Implements template_preprocess_responsive_images().
*/
function
uw_cfg_common_preprocess_responsive_image
(
&
$variables
)
{
// Get the current path.
$current_path
=
\Drupal
::
service
(
'path.current'
)
->
getPath
();
// Explode the current path so we can check where we are.
$current_path_parts
=
explode
(
'/'
,
$current_path
);
// If the current path has a node, we need to alter
// the image styles.
if
(
$current_path_parts
[
1
]
==
'node'
)
{
// Get the media library parameters, we will use this
// if we are on a media library page/modal.
$media_lib_parameters
=
\Drupal
::
request
()
->
query
->
get
(
'media_library_opener_parameters'
);
// If we are on a contact image, remove all styles
// but those for portraits.
if
(
$media_lib_parameters
[
'bundle'
]
==
'uw_ct_contact'
||
end
(
$current_path_parts
)
==
'uw_ct_contact'
)
{
// Get the styles used for portraits.
$uw_styles
=
\Drupal
::
service
(
'uw_cfg_common.uw_service'
)
->
getCropImageStyles
(
'portrait'
);
}
else
{
// Get the styles used for responsive.
$uw_styles
=
\Drupal
::
service
(
'uw_cfg_common.uw_service'
)
->
getCropImageStyles
(
'portrait'
);
}
// Step through each of the sources and see if we are.
// to use it.
foreach
(
$variables
[
'sources'
]
as
$index
=>
$source
)
{
// Get the srcset.
$srcset
=
$source
->
storage
()[
'srcset'
]
->
render
();
// Break into parts so that we can check for image styles.
$srcset_parts
=
explode
(
'/'
,
$srcset
);
// Step through each of the srcset parts.
foreach
(
$srcset_parts
as
$sp
)
{
// Ensure that we are on an image style.
if
(
strpos
(
$sp
,
'uw_is'
)
!==
FALSE
)
{
// If not in the list of image styles, remove
// it from the sources.
if
(
!
in_array
(
$sp
,
$uw_styles
))
{
unset
(
$variables
[
'sources'
][
$index
]);
}
}
}
}
}
}
/**
* Implements hook_form_alter().
*
...
...
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