I'm using Paragraphs to organise my content. A Project has many paragraphs. Each paragraph can be of type Text or Image (thanks to the paragraph type feature).

I want to expose my content to a REST API. So I created a view with a REST Export, listing projects.

Here's an example of the data i'm retrieving. This project has 3 paragraphs (called slides):

"title": "My Project title",
"field_slides": "<div class=\"item-list\"><ul><li>  <div data-quickedit-entity-id=\"paragraph/1\" class=\"paragraph paragraph--type--image paragraph--view-mode--default\">\n          \n  <div data-quickedit-field-id=\"paragraph/1/field_image/en/default\" class=\"field field--name-field-image field--type-image field--label-above\">\n    <div class=\"field__label\">Image</div>\n              <div class=\"field__item\">  <img src=\"/drupal-8.6.5/sites/default/files/2019-01/photo-1547213529-98a94130a2f3_0.jpeg\" width=\"1050\" height=\"700\" alt=\"\" typeof=\"foaf:Image\" />\n\n</div>\n          </div>\n\n      </div>\n</li><li>  <div data-quickedit-entity-id=\"paragraph/2\" class=\"paragraph paragraph--type--text paragraph--view-mode--default\">\n          \n  <div data-quickedit-field-id=\"paragraph/2/field_text/en/default\" class=\"clearfix text-formatted field field--name-field-text field--type-text-long field--label-above\">\n    <div class=\"field__label\">Text</div>\n              <div class=\"field__item\"><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p></div>\n          </div>\n\n      </div>\n</li><li>  <div data-quickedit-entity-id=\"paragraph/3\" class=\"paragraph paragraph--type--image paragraph--view-mode--default\">\n          \n  <div data-quickedit-field-id=\"paragraph/3/field_image/en/default\" class=\"field field--name-field-image field--type-image field--label-above\">\n    <div class=\"field__label\">Image</div>\n              <div class=\"field__item\">  <img src=\"/drupal-8.6.5/sites/default/files/2019-01/photo-1547253291-1337138b39e0.jpeg\" width=\"675\" height=\"901\" alt=\"\" typeof=\"foaf:Image\" />\n\n</div>\n          </div>\n\n      </div>\n</li></ul></div>"

All the slides are in a string. It also shows the edit links and some other html markup, and I can't use this format with my api client. Ideally, I'd need the slides to be separated (3 slides here so an array of 3 objects) and just show slide content (raw text or image url). That way I could consume my Api.

Any Idea how I can achieve this?

  • 1
    You’d need to create your own Normalizer class to deal with this (getting a custom response from a Views REST export). – Kevin Jan 17 at 12:25

Your Answer

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

Browse other questions tagged or ask your own question.