Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Here is a patch that adds 3 new settings to the entity forms: Media support, Media fields and Image styles.
- Media support enables/disables media reference field support.
- Media fields setting allows to define media reference fields.
- Image styles setting allows to add images in different image styles.
Comment | File | Size | Author |
---|---|---|---|
#69 | simple_sitemap_support_media_and_image_styles-2987748-69.patch | 12.2 KB | slasher13 |
#67 | interdiff.txt | 2.09 KB | slasher13 |
#67 | simple_sitemap_support_media_and_image_styles-2987748-67.patch | 24.71 KB | slasher13 |
#65 | 2987748_updated_patch_with_fid_fix.patch | 24.33 KB | FiNeX |
#60 | interdiff.txt | 5.19 KB | slasher13 |
Comments
Comment #2
angela_G CreditAttribution: angela_G commentedComment #4
gbyte CreditAttribution: gbyte as a volunteer and at gbyte commentedThanks for your patch! Would you mind uploading one for 8.x-3.x? New features go only into 3.x. I'll be happy to review and commit once the patch applies.
Comment #5
angela_G CreditAttribution: angela_G at EPAM Systems for Wolters Kluwer commentedHere is the patch for 8.x-3.x version.
Comment #6
angela_G CreditAttribution: angela_G at EPAM Systems for Wolters Kluwer commentedComment #7
slasher13re-roll
Comment #9
slasher13re-roll
Comment #11
drup16 CreditAttribution: drup16 commentedHi,
What is the problem we are trying to resolve with this patch?
Comment #12
angela_G CreditAttribution: angela_G at EPAM Systems for Wolters Kluwer commenteddrup16, this patch allows to include referenced Media images in the sitemap.
Also, it allows to select multiple image styles for the images.
Attaching an updated patch with errors fixed and a little bit changed functionality.
If entity doesn't have any Media field, the configuration form looks as below:
If entity has a Media field, the configuration form looks as below:
Comment #13
angela_G CreditAttribution: angela_G at EPAM Systems for Wolters Kluwer commentedComment #14
gbyte CreditAttribution: gbyte as a volunteer and at gbyte commented@angela_G Thanks for your patches!
As far as I understand the screenshots, for media images there is no need to choose an images style, but for core image fields a style can be chosen?
Comment #15
angela_G CreditAttribution: angela_G at EPAM Systems for Wolters Kluwer commented@gbyte.co Thank you for response.
Image styles are applied to both core and media images, since media images can have different view modes with different image styles.
What do you think?
Attaching another patch with test errors fixed.
Comment #16
angela_G CreditAttribution: angela_G at EPAM Systems for Wolters Kluwer commentedComment #17
slasher13re-roll
Comment #18
slasher13re-roll
Comment #19
rajeshwari10 CreditAttribution: rajeshwari10 as a volunteer and commentedComment #20
rajeshwari10 CreditAttribution: rajeshwari10 as a volunteer and commentedThe images_styles are added as an array in the config and its not been handled in the code. Because of which we get `Warning: Illegal offset type in Drupal\simple_sitemap\Form\FormHelper->displayEntitySettings() (line 416 of modules/contrib/simple_sitemap/src/Form/FormHelper.php)` Adding the patch for the same
Comment #21
gbyte CreditAttribution: gbyte as a volunteer and at gbyte commentedThanks @rajeshwari10, would you mind adding an interdiff?
Comment #22
slasher13Comment #23
catapipperI just tested this patch locally and I love what it's doing. Though I did find an issue where if the page doesn't have an image connected then the sitemap entry for the page disappears.
Steps to reproduce:
- Make a page with an image type and sitemap turned on with images by default
- Create a piece of content without an image
- Rebuild sitemap
You'll notice that this particular page/entity is missing from the sitemap.
Comment #24
slasher13Can't reproduce. see
From my pov your problem is not affected by this patch.
Comment #25
mathg16 CreditAttribution: mathg16 commentedI patched the code with #20 and found an issue where when selected no Image style you would get an error when trying to build the image url.
The error is at line 285 of EntityUrlGeneratorBase.php. Instead of
if (!empty($entity_settings['image_styles'])) {
you could useif (!empty(array_filter($entity_settings['image_styles']))) {
as the $entity_settings['image_styles'] equals ['' => ''] when no style is selected.Comment #26
m-si CreditAttribution: m-si commentedI can reproduce the findings of catapiper #23.
I used the patch of #20
sitemap 8.x-3.5
drupal 8.8.2
If one has slected the media field and the image style only for some content types all of the others are missing in the generated sitemap. If I don‘t select an image style it produces the issue #23 describes (I haven‘t tested his solution by now...
Comment #27
slasher13re-roll
Comment #28
slasher13Fix #23- please test
Comment #29
rmontero CreditAttribution: rmontero as a volunteer and commentedFor your consideration. I added a check for the existence of an `'image_styles'` key on the `$entity_settings` array.
Comment #30
mrinalini9 CreditAttribution: mrinalini9 at Srijan | A Material+ Company for Drupal India Association commentedRerolled patch #29 as it failed to apply, please review.
Comment #31
slasher13clean re-roll
Comment #32
slasher13added isset check (isset and is_array is sufficent in this case)
Comment #33
slasher13wrong interdiff.xt in #32
add correct interdiff.txt
Comment #34
slasher13Fix Warning: Illegal offset type in Drupal\simple_sitemap\Form\FormHelper->displayEntitySettings()
Comment #35
slasher13re-roll
Comment #36
mukesh.dev CreditAttribution: mukesh.dev commentedError:
The custom default base url was not implementing for image files.
Fixed this and updated patch #34 for version 3.7.0
Comment #37
mukesh.dev CreditAttribution: mukesh.dev commentedComment #38
mukesh.dev CreditAttribution: mukesh.dev commentedThe custom default base url was not implementing for image files. Fixed this and updated patch #35 for version 3.8.0
Comment #40
credevator CreditAttribution: credevator as a volunteer commentedAdd validation for checking if media exists or not to avoid error if media doesn't exist.
Comment #41
credevator CreditAttribution: credevator as a volunteer commentedComment #42
credevator CreditAttribution: credevator as a volunteer commentedComment #43
Shenron_segamag CreditAttribution: Shenron_segamag commentedAre there any settings to make it work ? I can't see the new fields in the sitemap settings of my node types after applying patch #40.
Comment #44
slasher13re-roll
Comment #45
slasher13re-roll
Comment #46
Shenron_segamag CreditAttribution: Shenron_segamag commentedStill no change for me (tested with 8.x-3.10).
Comment #47
marcoka CreditAttribution: marcoka commentedDo i understand this correctly. The module currently does not support adding images from a node that are added by entity reference. Like here: https://developers.google.com/search/docs/advanced/sitemaps/image-sitemapsThis patch has the goal to make that possible?
I applied the patch to the latest 3.1 and i get images added to the xml. Like this:
Looks good.
Warning: If you use this patch the contrub sitemap index module will not work no more, fix info is there
#3230211: Errors when creating
Would it make sense to hide the image row using the styles on the page the user views? Like adding this to the main css
I also think adding title/alt makes a lot of sense so we have descriptive images and not just images. It seems code add that but nothing is output even alt/title is present.
Code is inside "getEntityImageUrls"
Where media fields are looped using "fforeach ($entity->get($media_field)->getValue() as $value) {"
Later there is the alt and title set using $value['alt'] and $value['title']. These are always empty because $value only contians the target_id
If you add
$value['alt'] = $media->get($field->getName())->getValue()[0]['alt'];
$value['title'] = $media->get($field->getName())->getValue()[0]['title'];
above the existing $fid beeing loaded it will work.
$fid = $media->get($field->getName())->getValue()[0]['target_id'];
Just a quick look i took this night. What do you think?
Comment #48
gbyte CreditAttribution: gbyte as a volunteer and at gbyte commented3.x is feature complete now, let's focus on 4.x.
Comment #49
slasher13re-roll
Comment #50
slasher13typo
Comment #51
GiorgosK- Latest patch with version 4.0 applies cleanly (did not apply to latest version released a few days ago)
- have enabled image to be included in sitemap in basic page with default image style
- have created a node and added media image
- rebuild queue and generate sitemap from admin/config/search/simplesitemap but sitemap does not include any images
what am I missing ?
Comment #52
slasher13re-roll
@GiorgosK: It only works for entities. In sitemap configuration enable node entity and set entity type settings.
Comment #53
tedfordgif CreditAttribution: tedfordgif at WebFirst, Inc. commentedPatch in 52 results in PHP notices due to undefined index 'settings'. Updated patch attached.
Comment #54
WalkingDexter CreditAttribution: WalkingDexter as a volunteer and at Initlab commentedPatch #21 from #3152961: Image support for Paragraphs & Media also adds support for images from media entities.
A few thoughts about the current issue.
First of all we need to add general support. Settings for choosing fields and image styles can be taken out in a separate discussion. So far this seems to me like an unnecessary complication of the user interface. It might be better to move this feature to a hook level.
Comment #55
marcoka CreditAttribution: marcoka commentedTested #53 applied the
patch sucessfully to the latest 4.1 and latest 4.x-devComment #56
slasher13re-roll #53
Comment #57
slasher13Comment #58
slasher13Comment #60
slasher13Comment #61
slasher13Comment #62
jshimota01 CreditAttribution: jshimota01 commentedI am running 4.1-dev - on php 8.1.7 and Drupal 9.4.3. My sitemap.xml file has no media in it, although the patch create the expansion for paragraphs and media very nicely. I am using Paragraphs with w3css theme - images are handled via w3css Images library manager. All my images are stored this way.
All my media is Webp and managed under media library - while the images are available directly with file call, the w3css-mediawrapper call isn't being handled correctly. I guess the obvious question first, should I see these images in the sitemap? The second question, would duplicating the images into the basic media library as simple images - currently they are 'W3css-image' isn't being index I don't think. Am I doing this wrongly or are my expectations set incorrect?
Comment #63
FiNeX CreditAttribution: FiNeX as a volunteer commentedHi, I'm using the patch for media field on nodes and it looks fine. Thank you.
Comment #64
FiNeX CreditAttribution: FiNeX as a volunteer commentedHi, patch #60 is no longer applicable on version 4.1.6.
Comment #65
FiNeX CreditAttribution: FiNeX as a volunteer commentedHi, I've updated the patch and I've also added a quick fix when $fid variable is null.
Comment #67
slasher13fix test failures
Comment #68
FiNeX CreditAttribution: FiNeX as a volunteer commentedThank you @slasher for the updated patch! I've tested and it works fine on my use case.
Comment #69
slasher13re-roll
Comment #70
gbyte CreditAttribution: gbyte as a volunteer and at gbyte commentedThank you everyone for contributing.
I agree and I just commited #3152961: Image support for Paragraphs & Media. I appreciate that patches from this here issue allow for more configuration, but the current/linked solution basically extends the old generic functionality to work with paragraphs & media and does not exceed this module's scope (unlike the solution provided here).
Please test the dev version and get back to me in the other issue.