Hello everyone, how are you?

First of all; congrats on the project. It's very useful.

Problem/Motivation

Question; Does Simple XML Sitemap not have support for Paragraphs?

https://www.drupal.org/project/paragraphs

In our case, there are many Nodes with Paragraphs and inside of these Paragraphs, there are images and PDFs. But simple_sitemap isn't indexing it.

There is a possibility to index these Paragraphs with Images/PDFs?

Thanks in advanced

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

RenatoG created an issue. See original summary.

renatog’s picture

Title: Support for index paragraphs » Support for paragraphs
renatog’s picture

Issue summary: View changes
renatog’s picture

Issue summary: View changes
renatog’s picture

Issue summary: View changes
renatog’s picture

Issue summary: View changes
renatog’s picture

Issue summary: View changes
renatog’s picture

Issue summary: View changes
renatog’s picture

Title: Support for paragraphs » Support for Paragraphs
renatog’s picture

Issue summary: View changes
gbyte’s picture

As paragraphs are parts of a single page for a SEO sitemap you would not want to index the paragraph itself and you should be fine with indexing the actual webpage.

Images/pdfs could profit somewhat from being explicitely indexed in a sitemap, but there is no built in support for images inside of media or paragraphs yet. For media you might want to look at #2987748: Add Media images to sitemap.

However IMO if you are indexing the page the images/pdf's are at, google will pick those up.

renatog’s picture

Yeah, the idea isn't to index the paragraph. The idea is to index the page with images and pdf's (uploaded in Paragraphs)

So, for example, there is a page /node/7 and inside of this node there is a paragraph, and inside of this paragraph, there is an image and one PDF.

The sitemap.xml was generated with /node/7 indexed, but without image and without PDF (because they're inside of paragraph)

Well, thank you so much for your help. It's just a double check to check if there is a solution to files inside of Paragraphs.

Thanks a lot @gbyteco

felribeiro’s picture

Status: Active » Needs review
FileSize
3.3 KB
renatog’s picture

Category: Support request » Feature request
Status: Needs review » Reviewed & tested by the community

I was reviewed by our team and really works well!

Thank you so much @felribeiro

Have a good weekend

renatog’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
3.37 KB

Adding a small verification to check if paragraph was loaded

renatog’s picture

Berdir’s picture

Status: Needs review » Needs work
+++ b/src/Plugin/simple_sitemap/UrlGenerator/EntityUrlGeneratorBase.php
@@ -2,6 +2,8 @@
 namespace Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator;

@@ -222,22 +224,72 @@ abstract class EntityUrlGeneratorBase extends UrlGeneratorBase {
+  protected function getDataFromParagraphField(array &$image_data, ContentEntityBase $entity, FieldConfigBase $field) {
+    foreach ($entity->get($field->getName())->getValue() as $paragraph) {
+      $paragraph_entity = Paragraph::load($paragraph['target_id']);
+
+      // Check if paragraph was loaded.
+      if (empty($paragraph_entity)) {

use foreach ($entity->get($field->getName() as $item) and then $item->entity, no need to hardcode paragraphs.

I wouldn't pass in $field though but just the field name. The type hint is wrong anyway, this would fail hard if it's a base field.

That said, it might be better to optionally support the entity_usage project, you could just ask its APi to get all references of a certain type. Then you'd also support media entities for example.

renatog’s picture

Hello @berdir how are you?

Thank you so much for your feedback but sorry I didn't understand your points.

Could you try to explain using a different way, please?

edsoncarlos’s picture

VasiliyRepin’s picture

Version: 8.x-3.x-dev » 4.x-dev
FileSize
3.37 KB
WalkingDexter’s picture

WalkingDexter’s picture

Assigned: Unassigned » gbyte

Main points:

  • Images are searched by mime type. This allows us to not be limited to a specific field type.
  • The paragraph entity is checked by the ParagraphInterface, not by the field type. This works even if the "paragraphs" module is not enabled or if it's missing from the codebase (because that's how PHP works).
  • A similar check can be used for media entities.

@gbyte Your opinion is important here (as the module creator).

InaW’s picture

Reupload Patch for simple_sitemap version 4.1.2

Status: Needs review » Needs work

The last submitted patch, 23: support_for_paragraphs_4_1_2.patch, failed testing. View results

Manuel Garcia’s picture

Assigned: gbyte » Unassigned
Status: Needs work » Needs review
FileSize
2.84 KB

First, thanks all for the patch, I have been evaluating it and seems to work as advertised.

I had to reroll it so I am attaching the re-roll which should apply cleanly against 4.x.

De-assigning assuming this is no longer being worked by gbyte :)

gbyte’s picture

Assigned: Unassigned » gbyte

@ManuelGarcia @WalkingDexter So sorry, this slipped my mind. Will make a todo and look at it in October! Anyone feel free to look at the code and add your opinions!

  • gbyte committed e22cc5ee on 4.x
    Issue #3152961 by renatog, WalkingDexter, felribeiro, edsoncarlos,...
gbyte’s picture

Assigned: gbyte » Unassigned
Status: Needs review » Fixed

@WalkingDexter This is really neat, sorry I missed your contribution.

gbyte’s picture

Title: Support for Paragraphs » Image support for Paragraphs & Media
gbyte’s picture

@WalkingDexter I commited last night without giving you author attribution - is there a way to fix that?

WalkingDexter’s picture

@gbyte I don't think this is possible since the commit is already done. Don't worry, my contribution is already listed in the Git message.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.