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.
CommentFileSizeAuthor
#69 simple_sitemap_support_media_and_image_styles-2987748-69.patch12.2 KBslasher13
#67 interdiff.txt2.09 KBslasher13
#67 simple_sitemap_support_media_and_image_styles-2987748-67.patch24.71 KBslasher13
#65 2987748_updated_patch_with_fid_fix.patch24.33 KBFiNeX
#60 interdiff.txt5.19 KBslasher13
#60 simple_sitemap_support_media_and_image_styles-2987748-60.patch24.57 KBslasher13
#58 simple_sitemap_support_media_and_image_styles-2987748-58.patch23.93 KBslasher13
#57 simple_sitemap_support_media_and_image_styles-2987748-57.patch24.02 KBslasher13
#56 simple_sitemap_support_media_and_image_styles-2987748-56.patch24.02 KBslasher13
#53 simple_sitemap_support_media_and_image_styles-2987748-53.patch24.64 KBtedfordgif
#52 simple_sitemap_support_media_and_image_styles-52.patch24.68 KBslasher13
#50 simple_sitemap_support_media_and_image_styles-50.patch27.09 KBslasher13
#49 simple_sitemap_support_media_and_image_styles-49.patch27.04 KBslasher13
#45 simple_sitemap_support_media_and_image_styles-45.patch27.94 KBslasher13
#44 simple_sitemap_support_media_and_image_styles-44.patch27.79 KBslasher13
#40 simple_sitemap_support_media_and_image_styles-40.patch27.78 KBcredevator
#38 simple_sitemap_support_media_and_image_styles-38.patch27.68 KBmukesh.dev
#37 simple_sitemap_support_media_and_image_styles-37.patch27.77 KBmukesh.dev
#36 simple_sitemap_support_media_and_image_styles-37.patch32.54 KBmukesh.dev
#35 simple_sitemap_support_media_and_image_styles-35.patch27.61 KBslasher13
#34 interdiff.txt1.43 KBslasher13
#34 simple_sitemap_support_media_and_image_styles-34.patch27.71 KBslasher13
#33 interdiff.txt908 bytesslasher13
#32 interdiff.txt1.88 KBslasher13
#32 simple_sitemap_support_media_and_image_styles-32.patch27.58 KBslasher13
#31 simple_sitemap_support_media_and_image_styles-31.patch27.54 KBslasher13
#30 simple_sitemap_support_media_and_image_styles-30.patch27.59 KBmrinalini9
#29 simple_sitemap_support_media_and_image_styles-29.patch27.59 KBrmontero
#28 interdiff.txt1.88 KBslasher13
#28 simple_sitemap_support_media_and_image_styles-28.patch27.54 KBslasher13
#27 simple_sitemap_support_media_and_image_styles-27.patch27.5 KBslasher13
#22 interdiff.txt1.19 KBslasher13
#20 simple_sitemap_support_media_and_image_styles-20.patch27.55 KBrajeshwari10
#18 simple_sitemap_support_media_and_image_styles-18.patch27.42 KBslasher13
#17 simple_sitemap_support_media_and_image_styles-17.patch14.93 KBslasher13
#16 simple_sitemap_support_media_and_image_styles-16.patch14.93 KBangela_G
#15 simple_sitemap_support_media_and_image_styles-15.patch14.81 KBangela_G
#13 simple_sitemap_support_media_and_image_styles-12.patch14.93 KBangela_G
#12 simple_sitemap_support_media_and_image_styles-12.patch14.92 KBangela_G
#12 Simple_Sitemap_2.PNG43.69 KBangela_G
#12 Simple_Sitemap_1.PNG42.03 KBangela_G
#9 simple_sitemap_support_media_and_image_styles-9.patch14.75 KBslasher13
#7 simple_sitemap_support_media_and_image_styles_8_x_3-7.patch19.97 KBslasher13
#5 simple_sitemap_support_media_and_image_styles_8_x_3.patch20.08 KBangela_G
#2 simple_sitemap_support_media_and_image_styles.patch20.24 KBangela_G
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

angela_G created an issue. See original summary.

angela_G’s picture

Status: Needs review » Needs work

The last submitted patch, 2: simple_sitemap_support_media_and_image_styles.patch, failed testing. View results

gbyte’s picture

Version: 8.x-2.x-dev » 8.x-3.x-dev

Thanks 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.

angela_G’s picture

Here is the patch for 8.x-3.x version.

angela_G’s picture

Status: Needs work » Needs review
slasher13’s picture

Status: Needs review » Needs work

The last submitted patch, 7: simple_sitemap_support_media_and_image_styles_8_x_3-7.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

slasher13’s picture

Status: Needs work » Needs review
FileSize
14.75 KB

re-roll

Status: Needs review » Needs work

The last submitted patch, 9: simple_sitemap_support_media_and_image_styles-9.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

drup16’s picture

Hi,

What is the problem we are trying to resolve with this patch?

angela_G’s picture

drup16, 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:
Form 1

If entity has a Media field, the configuration form looks as below:
Form 2

angela_G’s picture

gbyte’s picture

@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?

  • Why does it allow to choose multiple styles?
  • Would it make more sense to unclutter the UI by including all media fields and not let the user choose which media fields to include? For regular sitemaps you usually want all images displayed on the website to be included.
  • Also we should discuss if not to remove support for regular image fields altogether.
angela_G’s picture

@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.

  • The ability to select multiple image styles is just a feature. For example, in our project, the SEO specialist requested a certain list of image styles in the sitemap.
  • Since the media field can refer to various types of multimedia, such as video or file, selection of media fields in the settings allows to specify more accurate results. For example, imagine a media video field that contains two fields: a link to a video and a thumbnail image that should not be included in the sitemap.
  • I think many sites use core images as well as media images.

What do you think?

Attaching another patch with test errors fixed.

angela_G’s picture

slasher13’s picture

Status: Needs work » Needs review
FileSize
14.93 KB

re-roll

slasher13’s picture

rajeshwari10’s picture

Status: Needs review » Needs work
rajeshwari10’s picture

Status: Needs work » Needs review
FileSize
27.55 KB

The 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

gbyte’s picture

Thanks @rajeshwari10, would you mind adding an interdiff?

slasher13’s picture

FileSize
1.19 KB
catapipper’s picture

I 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.

slasher13’s picture

Can't reproduce. see

    // Add images if any.
    if (!empty($url_data['images'])) {
      foreach ($url_data['images'] as $image) {
        $this->writer->startElement('image:image');
        $this->writer->writeElement('image:loc', $image['path']);
        if (strlen($image['title']) > 0) {
          $this->writer->writeElement('image:title', $image['title']);
        }
        if (strlen($image['alt']) > 0) {
          $this->writer->writeElement('image:caption', $image['alt']);
        }
        $this->writer->endElement();
      }
    }
  }

From my pov your problem is not affected by this patch.

mathg16’s picture

I 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 use if (!empty(array_filter($entity_settings['image_styles']))) { as the $entity_settings['image_styles'] equals ['' => ''] when no style is selected.

m-si’s picture

I 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...

slasher13’s picture

slasher13’s picture

rmontero’s picture

For your consideration. I added a check for the existence of an `'image_styles'` key on the `$entity_settings` array.

array_key_exists('image_styles', $entity_settings) && 
mrinalini9’s picture

Rerolled patch #29 as it failed to apply, please review.

slasher13’s picture

slasher13’s picture

added isset check (isset and is_array is sufficent in this case)

slasher13’s picture

FileSize
908 bytes

wrong interdiff.xt in #32

add correct interdiff.txt

slasher13’s picture

Fix Warning: Illegal offset type in Drupal\simple_sitemap\Form\FormHelper->displayEntitySettings()

slasher13’s picture

mukesh.dev’s picture

Error:
The custom default base url was not implementing for image files.

Fixed this and updated patch #34 for version 3.7.0

mukesh.dev’s picture

The custom default base url was not implementing for image files. Fixed this and updated patch #35 for version 3.8.0

Status: Needs review » Needs work

The last submitted patch, 38: simple_sitemap_support_media_and_image_styles-38.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

credevator’s picture

Assigned: Unassigned » credevator
Status: Needs work » Patch (to be ported)
FileSize
27.78 KB

Add validation for checking if media exists or not to avoid error if media doesn't exist.

credevator’s picture

Status: Patch (to be ported) » Needs review
credevator’s picture

Assigned: credevator » Unassigned
Shenron_segamag’s picture

Are 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.

slasher13’s picture

slasher13’s picture

Shenron_segamag’s picture

Still no change for me (tested with 8.x-3.10).

marcoka’s picture

Do 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-sitemaps

This 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:

<image:image>
   <image:loc>http://dev9.abc.de/sites/funkkopfhoerer-infos.de/files/test-galeriebilder/sony_mdr_ds6500_8128.jpg</image:loc>
  </image:image>
  <image:image>
   <image:loc>http://dev9.abc.de/sites/funkkopfhoerer-infos.de/files/test-galeriebilder/sony_mdr_ds6500_8130.jpg</image:loc>
  </image:image>

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

  table ul.images{
  display: none;
}

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?

gbyte’s picture

Version: 8.x-3.x-dev » 4.x-dev
Status: Needs review » Needs work

3.x is feature complete now, let's focus on 4.x.

slasher13’s picture

re-roll

slasher13’s picture

GiorgosK’s picture

- 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 ?

slasher13’s picture

re-roll

@GiorgosK: It only works for entities. In sitemap configuration enable node entity and set entity type settings.

tedfordgif’s picture

Patch in 52 results in PHP notices due to undefined index 'settings'. Updated patch attached.

WalkingDexter’s picture

Patch #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.

marcoka’s picture

Tested #53 applied the patch sucessfully to the latest 4.1 and latest 4.x-dev

slasher13’s picture

slasher13’s picture

slasher13’s picture

Status: Needs review » Needs work
slasher13’s picture

slasher13’s picture

Status: Needs work » Needs review
jshimota01’s picture

I 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?

FiNeX’s picture

Hi, I'm using the patch for media field on nodes and it looks fine. Thank you.

FiNeX’s picture

Hi, patch #60 is no longer applicable on version 4.1.6.

FiNeX’s picture

Hi, I've updated the patch and I've also added a quick fix when $fid variable is null.

Status: Needs review » Needs work

The last submitted patch, 65: 2987748_updated_patch_with_fid_fix.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

slasher13’s picture

fix test failures

FiNeX’s picture

Thank you @slasher for the updated patch! I've tested and it works fine on my use case.

slasher13’s picture

gbyte’s picture

Status: Needs review » Closed (outdated)
Related issues: +#3152961: Image support for Paragraphs & Media

Thank you everyone for contributing.

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.

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.