0

On my Drupal 9 installation, I created nodes with Media images integrated with CKEditor. This is not an image field in the node type, but an image embedded in node content with Media and CKEditor.

How do I create a block on the node page which displays all the images integrated into the node?

I can display the images of the node that would be used in an image field, but I have not been able to display the ones that are integrated directly into the content with Media and CKEditor.

1 Answer 1

1

Media images that are embedded with CKEditor into a text field are referenced using <drupal-media> tags. These tags are parsed by an input filter when the node is rendered. So, as far as I know, there is no way (in core or in contrib) to generate a list of the embedded media and then process that with the Views module.

With an Image field, it works because there is an entity reference, and Views can handle those.

So, if you need a list of the images used in a node, you could either write code to extend Views to process the <drupal-media> tags (probably quite a pain), or restructure your content/don't use the embed feature and use entity references instead.

5
  • I would like to present my pages like this site wonderfall.space/grapheneos-12-1-apps with photos and summary of embedded content. In my case it is to make a type of node "Point of interest". The photos contain coordinates and I want to set up a views block on the page with a map and the photos contained in the nodes displayed on it.
    – zoulou66
    Jun 13 at 10:06
  • So the solution is to use Paragraph? The problem is that it's not intuitive like CKEditor and it's less suited to creating content on mobile.
    – zoulou66
    Jun 13 at 10:07
  • I'm not sure what the solution is because it depends on the detailed requirements, which were not in the original question. You asked how to get a list of media embedded in CKEditor, and I explained why that is not easy to do. If you need images in the content and a list for a view, one way to do it would be to add an entity reference field and add all the images that you embed into the CKEditor field into the entity reference field as well. This is duplication but as I said there's no good way to get the list of images from CKEditor. Jun 13 at 11:30
  • keny Thanks, yes I think I will create an additional hidden field. Too bad because it's pointless work. Do you know if Media CKEditor will be usable in Views in the future? Or if A relationship with CKEditor is in progress?
    – zoulou66
    Jun 13 at 13:27
  • I think that in general, trying to work with content embedded by CKEditor is a poor user experience and it is unlikely to get better in the future. In general, I would avoid embedding as an approach (I tried to do a similar thing before and gave up.) If you have a relatively simple structure like "text - node summaries - text", one way to do it without paragraphs is to add two text fields (top text, bottom text) + 1 entity reference field, and then use Layout Builder to embed your view using the entity reference. This can be done using only Drupal core. Jun 13 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.