Hello,

we try to make a multi-level export in JSON, like this :

{
    "timeline":
    {
       "type":"default",
       "startDate":"2012,1,26",
       "date": [
           {
               "startDate":"2011,12,12",
               "endDate":"2012,1,27",
               "headline":"Vine",
               "text":"<p>Vine Test</p>",
               "asset":
               {
                   "media":"../source/gfx/interior.jpg",
                   "thumbnail":"../source/gfx/soleil.jpg"
               }
           },
           {
               "startDate":"2012,1,26",
               "endDate":"2012,1,27",
               "headline":"Exhibition",
               "asset":
               {
                   "media":"http://www.youtube.com/watch?v=6kRdjIFfJqk",
                   "credit":"some credits here"
               }
           }

           

       ]

    }

}

but we dont know how to do it. is-it possible ? How can we configure that in the views fields ?

thank you for your help

Comments

sonoutlaw’s picture

I'm try to do the same for timeline.js . Don't want to use the timeline module, just want to be able to export the multi-level JSON file it requires as shown above in Matthieus' post.

Any ideas?

anthonylindsay’s picture

I could not see a way to do it with views_datasource.

I had to create a custom module to do it. I created a view that pulled in the NIDs of all the elements I wanted in my timeline, then called the view with views_get_view_result.

I set up the json preamble as a string down to the start of the array of events and then looped through my views data like this:

foreach ($view_result as $item) {
    $entity_nid = $item->entity;
    $entity = entity_metadata_wrapper('node', $entity_nid);
    ....
}
 

Adding to my json data string as needed and including the items from my nodes. Then I closed off the json and did drupal_add_js to call the timeline javascript files and added my json as a setting with drupal_add_js(array('myModule' => array('timeline_data_object' => $json_data_object)), 'setting');

Works a treat, but does involve a custom module.

anthonylindsay’s picture

Status: Active » Closed (won't fix)

Closing this as I don't think this type of multi level configuration is feasible within views_datasource, whilst keeping it generic and therefore useful.