Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
views_rss
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
views_rss
Commits
418e2a5b
Commit
418e2a5b
authored
Jun 14, 2023
by
Damien McKenna
Committed by
Damien McKenna
Jun 14, 2023
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3366706
by DamienMcKenna: Add support for media fields in media:thumbnail.
parent
91dddb0e
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
CHANGELOG.txt
+1
-0
1 addition, 0 deletions
CHANGELOG.txt
modules/views_rss_media/views_rss_media.inc
+30
-9
30 additions, 9 deletions
modules/views_rss_media/views_rss_media.inc
with
31 additions
and
9 deletions
CHANGELOG.txt
+
1
−
0
View file @
418e2a5b
...
...
@@ -3,6 +3,7 @@ Advanced Views RSS Feed 8.x-2.x-dev, 2022-xx-xx
#3365915 by DamienMcKenna: Merge Views RSS Media submodules.
#3299453 by afsch, DamienMcKenna, Project Update Bot: Automated Drupal 10
compatibility fixes for media submodules.
#3366706 by DamienMcKenna: Add support for media fields in media:thumbnail.
Advanced Views RSS Feed 8.x-2.0, 2023-06-14
...
...
This diff is collapsed.
Click to expand it.
modules/views_rss_media/views_rss_media.inc
+
30
−
9
View file @
418e2a5b
...
...
@@ -5,6 +5,7 @@
* Preprocess functions for Views RSS: Media Elements module.
*/
use
Drupal\file\Entity\File
;
use
Drupal\file\FileInterface
;
use
Drupal\image\Entity\ImageStyle
;
...
...
@@ -96,26 +97,27 @@ function views_rss_media_preprocess_item_thumbnail(&$variables) {
$variables
[
'elements'
]
=
array
();
foreach
(
$variables
[
'raw'
][
'items'
]
as
$item
)
{
// Start building RSS element.
$element
=
array
(
'key'
=>
'media:thumbnail'
,
'attributes'
=>
array
(),
);
// File fields.
$file
=
NULL
;
if
(
!
empty
(
$item
[
'rendered'
][
'#file'
]))
{
$file
=
$item
[
'rendered'
][
'#file'
];
}
// Image fields.
if
(
!
empty
(
$item
[
'rendered'
][
'#item'
]
->
entity
))
{
else
if
(
!
empty
(
$item
[
'rendered'
][
'#item'
]
->
entity
))
{
$file
=
$item
[
'rendered'
][
'#item'
]
->
entity
;
}
// Start building RSS element.
$element
=
array
(
'key'
=>
'media:thumbnail'
,
'attributes'
=>
array
(),
);
// File entity found.
if
(
!
empty
(
$file
))
{
// Image style is defined, need to link to resized version.
if
(
$image_style_name
=
$item
[
'rendered'
][
'#image_style'
])
{
$image_style
=
ImageStyle
::
load
(
$image_style
_name
);
if
(
!
empty
(
$item
[
'rendered'
][
'#image_style'
])
)
{
$image_style
=
ImageStyle
::
load
(
$
item
[
'rendered'
][
'#
image_style
'
]
);
$element
[
'attributes'
][
'url'
]
=
\Drupal
::
service
(
'file_url_generator'
)
->
generateAbsoluteString
(
$image_style
->
buildUri
(
$file
->
getFileUri
()));
}
// Normal image size.
...
...
@@ -123,6 +125,25 @@ function views_rss_media_preprocess_item_thumbnail(&$variables) {
$element
[
'attributes'
][
'url'
]
=
$file
->
createFileUrl
(
FALSE
);
}
}
// Media fields.
elseif
(
!
empty
(
$item
[
'rendered'
][
'#media'
]))
{
// Render the output so the URL can be extracted.
$output
=
\Drupal
::
service
(
'renderer'
)
->
renderPlain
(
$item
[
'rendered'
],
FALSE
);
// Extract the URL from the output string.
preg_match
(
'/src="(.*)" width="(.*)" height="(.*)" alt="([^"]*)"/'
,
$output
,
$matches
);
if
(
!
empty
(
$matches
))
{
$element
[
'attributes'
][
'url'
]
=
$matches
[
1
];
$element
[
'attributes'
][
'width'
]
=
$matches
[
2
];
$element
[
'attributes'
][
'height'
]
=
$matches
[
3
];
// @todo Work out a better location for this.
// @code
// $element['attributes']['title'] = $matches[4];
// @endcode
}
}
// No file entity found, but something still was assigned to be displayed
// as enclosure, so we just put its value in the url attribute.
elseif
(
!
empty
(
$item
[
'rendered'
][
'#markup'
]))
{
...
...
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