Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
responsive_image_style_builder
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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
responsive_image_style_builder
Merge requests
!5
Issue
#3494558
: Copy image style effects optional when editing an image style effect.
Code
Review changes
Check out branch
Open in Workspace
Download
Patches
Plain diff
Expand sidebar
Closed
Issue
#3494558
: Copy image style effects optional when editing an image style effect.
issue/responsive_image_style_builder-3494558:3494558-copy-image-style
into
1.0.x
Overview
0
Commits
2
Pipelines
0
Changes
1
Closed
Issue #3494558: Copy image style effects optional when editing an image style effect.
Gaurav Gupta
requested to merge
issue/responsive_image_style_builder-3494558:3494558-copy-image-style
into
1.0.x
7 months ago
Overview
0
Commits
2
Pipelines
0
Changes
1
Closes
#3494558
0
0
Merge request reports
Compare
1.0.x
version 1
43e7fb1f
7 months ago
1.0.x (base)
and
latest version
latest version
b91ace81
2 commits,
7 months ago
version 1
43e7fb1f
1 commit,
7 months ago
1 file
+
71
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
responsive_image_style_builder.module
+
71
−
0
View file @ b91ace81
Edit in single-file editor
Open in Web IDE
Show full file
@@ -155,3 +155,74 @@ function responsive_image_style_builder_form_image_style_add_parent_effect_submi
$derivativeStyle
->
save
();
}
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function
responsive_image_style_builder_form_image_effect_form_alter
(
&
$form
,
FormStateInterface
$form_state
)
{
// Get current image style from route
$current_style
=
\Drupal
::
routeMatch
()
->
getParameter
(
'image_style'
)
->
id
();
if
(
!
str_ends_with
(
$current_style
,
'_default'
))
{
return
;
}
$form
[
'copy_to_children'
]
=
[
'#type'
=>
'checkbox'
,
'#title'
=>
t
(
'Copy to derivative image styles'
),
'#description'
=>
t
(
'Apply these effect settings to all derivative image styles.'
),
'#default_value'
=>
FALSE
,
'#weight'
=>
99
,
];
$form
[
'#submit'
][]
=
'responsive_image_style_builder_effect_form_submit'
;
}
/**
* Custom submit handler for the image effect form.
*/
function
responsive_image_style_builder_effect_form_submit
(
array
$form
,
FormStateInterface
$form_state
)
{
if
(
!
$form_state
->
getValue
(
'copy_to_children'
))
{
return
;
}
// Get the current effect data
$effect_data
=
$form_state
->
getValue
(
'data'
);
$effect_id
=
$form_state
->
getValue
(
'id'
);
$effect_weight
=
$form_state
->
getValue
(
'weight'
);
// Get current image style and its derivatives
$current_style
=
\Drupal
::
routeMatch
()
->
getParameter
(
'image_style'
);
$derivative_styles
=
\Drupal
::
service
(
'risb.builder'
)
->
getDerivativeImageStyles
(
$current_style
->
id
());
$updated_styles
=
0
;
foreach
(
$derivative_styles
as
$derivative_style
)
{
// Find if effect already exists in derivative
$existing_effect
=
NULL
;
foreach
(
$derivative_style
->
getEffects
()
as
$existing
)
{
if
(
$existing
->
getConfiguration
()[
'id'
]
===
$effect_id
)
{
$existing_effect
=
$existing
;
break
;
}
}
if
(
$existing_effect
)
{
// Update only if effect exists
$configuration
=
$existing_effect
->
getConfiguration
();
$configuration
[
'data'
]
=
$effect_data
;
$configuration
[
'weight'
]
=
$effect_weight
;
$derivative_style
->
deleteImageEffect
(
$existing_effect
);
$derivative_style
->
addImageEffect
(
$configuration
);
$derivative_style
->
save
();
$updated_styles
++
;
}
}
if
(
$updated_styles
>
0
)
{
\Drupal
::
messenger
()
->
addMessage
(
t
(
'Effect configuration has been updated in @count derivative image styles.'
,
[
'@count'
=>
$updated_styles
]));
}
else
{
\Drupal
::
messenger
()
->
addWarning
(
t
(
'No derivative styles found with this effect to update.'
));
}
}
Loading