0

I'm using Drupal 8.6 and I'm doing the serialization of a node. This node has related fields, which I also would like to serialize. In my case I have an article which has a photo gallery which has many media objects.

I would like to serialize all the fields of the article, and then all the field of the photo gallery and then all the media. I'm using this code to serialize:

$serializer = \Drupal::service('serializer');
$data = $serializer->serialize($node, 'json', ['plugin_id' => 'entity']);

And in the photo gallery I'm getting this:

"field_album":[  
      {  
         "target_id":1019,
         "target_type":"node",
         "target_uuid":"5b721c12-0181-4f5f-bcd0-8fc53848bd91",
         "url":"\/medias\/xyz-123"
      }
   ],

Here I would like to have all the fields of the gallery and then all the field of the medias.

How can I achieve that? Thanks for any help

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.