You are here

function scald_atom_fetch_atoms in Scald: Media Management made easy 7

Fetch atoms and return in JSON format.

Parameters

string $sids: Comma separated list of atom ids.

Other parameters, such as context, could also be passed via the querystring.

1 string reference to 'scald_atom_fetch_atoms'
scald_menu in ./scald.module
Implements hook_menu().

File

includes/scald.pages.inc, line 509
This file contains the various callbacks related to Scald defined pages.

Code

function scald_atom_fetch_atoms($sids) {
  $output = array();
  $atoms = scald_atom_load_multiple(explode(',', $sids));

  // Context can be passed via the querystring.
  $context = isset($_GET['context']) && array_key_exists($_GET['context'], scald_contexts_public()) ? $_GET['context'] : '';
  foreach ($atoms as $sid => $atom) {
    $output[$sid] = array(
      'sid' => $sid,
      'contexts' => $context ? array(
        $context => scald_render($atom, $context),
      ) : array(),
      'meta' => array(
        'title' => $atom->title,
        'type' => $atom->type,
        'data' => !empty($atom->data) ? $atom->data : array(),
      ),
      'actions' => array_keys(scald_atom_actions_available($atom)),
    );
  }
  drupal_json_output($output);
}