When using the Element API, how do you go about using the Embedded Assets plugin?

With a regular asset, in the API transformer you can pull out assets and include them like this:

'transformer' => function(craft\elements\Entry $entry) {
    // Create an array of all the photo URLs
    $photos = [];
    foreach ($entry->photos->all() as $photo) {
        $photos[] = $photo->url;

    return [
        'title' => $entry->title,
        'url' => $entry->url,
        'description' => (string)$entry->description,
        'photos' => $photos

This approach however gives me the URL to the json file that Embedded Assets uses to store some information about the video.

Is there a better way than parsing that file as json in php and pulling the iframe from that? Is there some plugin code that can be used to handle this more elegantly?

  • Hi James, what are you trying to get out of the Embed Assets and return?
    – CraftQuest
    Nov 8, 2018 at 20:32
  • Hi Ryan. I'm hoping to pull out either the "code" attribute (the iframe). I know I could parse the json file and pull it out that way, but I imagine there's a "proper" way to do it using plugin code.
    – JamesNZ
    Nov 13, 2018 at 3:40


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.