1

I have a content type with a text field that uses CKEditor, in the editor is possible to add a media entity image, once the image is inserted inside the text the html tag for it is:

<p>Document</p>\r\n\r\n<drupal-entity alt=\"Luz\" data-embed-button=\"media_browser\" data-entity-embed-display=\"media_image\" data-entity-embed-display-settings=\"{&quot;image_style&quot;:&quot;&quot;,&quot;image_link&quot;:&quot;&quot;}\" data-entity-type=\"media\" data-entity-uuid=\"4076130e-9ccb-43f1-a4d9-dc8176271ffa\" title=\"Luz\"></drupal-entity>\r\n

I have in the site a webservice that need to provide the text field with all the information, but I need to convert the drupal-entity tag into an img tag to provide a tag that can be used from the applications that use the webservice.

I made a search inside the CKEditor configurations and in the media module but I can't find any related to this, how can I convert the drupal-entity tag into an img tag?

  • This should be done by applying a text format which has the "Display embedded entities" text filter enabled. – Hudri May 17 '18 at 17:32
  • I have the text format applied but is the same. I can see the image without problems but the field value is the same. – Adrian Cid Almaguer May 17 '18 at 17:36
  • 2
    If you still see the token then the text filter @Hudri mentioned is not applied. So this is either a configuration problem in the text format or the webservice doesn't use the processed field output, a feature added to core recently, see "processed" property of text fields now available in REST – 4k4 May 17 '18 at 18:35
1

Basically you'll want to get the field's value and do a str_replace(), but where?

I haven't done this myself yet, but I believe you'll have to create a normalizer.

Serialization API overview (good read).

I think you can achieve it by doing the following Changing the way Serializer handles entities.

There is more indepth info here Using Normalizers to Alter REST JSON Structure in Drupal 8.

  • Thanks for your answer, I will check the links and if I found the answer I will write some feedback. – Adrian Cid Almaguer May 17 '18 at 17:42

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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