Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bg_image_formatter
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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
bg_image_formatter
Commits
c9fcb5cc
Commit
c9fcb5cc
authored
2 months ago
by
Edouard Cunibil
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3216397
by tbenice, duaelfr: Allow all preprocess functions to modify...
parent
d00508ef
No related branches found
No related tags found
1 merge request
!15
Issue #3216397 by tbenice, duaelfr: Allow all preprocess functions to modify...
Pipeline
#462421
passed
2 months ago
Stage: build
Stage: validate
Stage: test
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/responsive_bg_image_formatter/src/Plugin/Field/FieldFormatter/ResponsiveBgImageFormatter.php
+32
-5
32 additions, 5 deletions
...lugin/Field/FieldFormatter/ResponsiveBgImageFormatter.php
with
32 additions
and
5 deletions
modules/responsive_bg_image_formatter/src/Plugin/Field/FieldFormatter/ResponsiveBgImageFormatter.php
+
32
−
5
View file @
c9fcb5cc
...
...
@@ -8,8 +8,10 @@ use Drupal\bg_image_formatter\Plugin\Field\FieldFormatter\BgImageFormatter;
use
Drupal\Core\Field\FieldItemListInterface
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Render\Markup
;
use
Drupal\Core\Theme\Registry
;
use
Drupal\Core\Url
;
use
Drupal\responsive_image
\Entity\ResponsiveImageStyle
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
* Responsive Background Image formatter.
...
...
@@ -22,6 +24,22 @@ use Drupal\responsive_image\Entity\ResponsiveImageStyle;
*/
class
ResponsiveBgImageFormatter
extends
BgImageFormatter
{
/**
* The theme registry service.
*
* @var \Drupal\Core\Theme\Registry
*/
protected
Registry
$registry
;
/**
* {@inheritdoc}
*/
public
static
function
create
(
ContainerInterface
$container
,
array
$configuration
,
$plugin_id
,
$plugin_definition
)
{
$instance
=
parent
::
create
(
$container
,
$configuration
,
$plugin_id
,
$plugin_definition
);
$instance
->
registry
=
$container
->
get
(
'theme.registry'
);
return
$instance
;
}
/**
* {@inheritdoc}
*/
...
...
@@ -102,23 +120,32 @@ class ResponsiveBgImageFormatter extends BgImageFormatter {
static
::
$selectorIndex
[
$field_id
]
++
;
$uri
=
$file
->
getFileUri
();
$vars
=
[
$var
iable
s
=
[
'uri'
=>
$file
->
getFileUri
(),
'responsive_image_style_id'
=>
$settings
[
'image_style'
],
'width'
=>
1
,
'height'
=>
1
,
];
if
(
file_exists
(
$uri
))
{
[
$vars
[
'width'
],
$vars
[
'height'
]]
=
getimagesize
(
$uri
);
[
$variables
[
'width'
],
$variables
[
'height'
]]
=
getimagesize
(
$uri
);
}
// Call preprocess functions to let other modules/themes react before
// rendering.
$info
=
$this
->
registry
->
get
();
$hook
=
'responsive_image__responsive_bg_image_formatter'
;
foreach
(
$info
[
'responsive_image'
][
'preprocess functions'
]
as
$preprocessor_function
)
{
if
(
is_callable
(
$preprocessor_function
))
{
call_user_func_array
(
$preprocessor_function
,
[
&
$variables
,
$hook
,
$info
]);
}
}
template_preprocess_responsive_image
(
$vars
);
if
(
empty
(
$vars
[
'sources'
]))
{
if
(
empty
(
$var
iable
s
[
'sources'
]))
{
continue
;
}
// Split each source into multiple rules.
foreach
(
array_reverse
(
$vars
[
'sources'
])
as
$source_i
=>
$source
)
{
foreach
(
array_reverse
(
$var
iable
s
[
'sources'
])
as
$source_i
=>
$source
)
{
$attr
=
$source
->
toArray
();
$srcset
=
explode
(
', '
,
$attr
[
'srcset'
]);
...
...
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