You are here

scald_provider_api.txt in Scald: Media Management made easy 6

Scald Provider API Documentation
================================================================================

Scald Core Version: 0.7
Documentation Updated: 2009-05-05

NOTE: For a general understanding of Scald's architecture, definitions of
      various terms, or additional information about the use of Scald, please
      reference docs/scald_overview.txt

Contents
--------
1 Conventions
2 Scald Hooks
3 Scald Hook Example Implementations
4 Scald Hook Execution Stack




1 CONVENTIONS
=============

  Throughout this spec, various parameters or members will be marked as
"Public", "Admin", or "Dev" (for instance the display title of the Unified
Type).  Anything which is marked as "Public" will be visible to the average User
of Scald.  Most items marked "Public" are also configurable by Admins (e.g. your
"Really cool" Unified Type might get overriden to "Really stupid" in the Admin
interface).  Finally, items marked "Dev" are not explicitly intended for display
to Admins or the Public.




2 SCALD HOOKS
=============

  Below are the function declarations for all Scald Core hooks grouped by Scald
Provider type.  Hooks which are common to multiple types are listed in each
section.  See "SCALD CORE HOOK EXAMPLE IMPLEMENTATIONS" for specifics about each
hook.  For hooks with the $mode parameter, $mode will be one of: type, atom,
context, transcoder, relationship, action.

<?php

// Type Provider Hooks
function hook_scald_provider();
function hook_scald_register_atom(&$atom, &$values, $mode);
function hook_scald_update_atom(&$atom, &$values, $mode);
function hook_scald_unregister_atom($atom, $mode);
function hook_scald_fetch(&$atom, $mode);
function hook_scald_prerender(&$atom, $mode);

// Atom Provider Hooks
function hook_scald_provider();
function hook_scald_register_atom(&$atom, &$values $mode);
function hook_scald_update_atom(&$atom, &$values, $mode);
function hook_scald_unregister_atom($atom, $mode);
function hook_scald_fetch(&$atom, $mode);
function hook_scald_prerender(&$atom, $mode);
function hook_scald_action(&$atom, $action, $mode);

// Context Provider Hooks
function hook_scald_provider();
function hook_scald_prerender(&$atom, $context, $options, $mode);
function hook_scald_render($atom, $context, $options);
function hook_scald_rendered_to_sas_LANGUAGE($text);

// Transcoder Provider Hooks
function hook_scald_provider();
function hook_scald_register_atom($atom, &$values, $mode);
function hook_scald_update_atom($atom, &$values, $mode);
function hook_scald_unregister_atom($atom, $mode);
function hook_scald_prerender(&$atom, $mode);

// Relationship Provider Hooks
function hook_scald_provider();
function hook_scald_register_atom(&$atom, &$values, $mode);
function hook_scald_update_atom(&$atom, &$values, $mode);
function hook_scald_unregister_atom($atom, $mode);

// Action Provider Hooks
function hook_scald_provider();
function hook_scald_action(&$atom, $action, $mode);

// Quick links
function hook_scald_atom_quickadd();

?>




3 SCALD HOOK EXAMPLE IMPLEMENTATIONS
====================================

  Below are sample implementations for each of the Scald Core hooks.  Hooks
which might be implemented by more than one type of Scald Provider are shown
as if the implementing module advertised each possible type of Scald Provider.

<?php
/**
 * Advertise what Scald Providers this module implements to Scald Core.
 *
 * A module can define zero or more Scald Providers of each Provider Type (more
 *  than one slug/definition array can be included in each provider-type array).
 *
 * NOTE: Scald Context Providers: specifying formats for types is
 *   only necessary if the Context is going to do something specific with the
 *   data included in Scald Atoms of that type.  If no format is specified for
 *   a given type by default, one can be specified in the Admin interface, but
 *   it is not required.  In fact, it is discouraged because the more formats
 *   that are specified for Scald Contexts, the more work the Transcoders need
 *   to do.
 *
 * @return
 *  A structured array which includes the required data for the Provisions
 *   provided by the Scald Provider.  The array takes the format indicated
 *   below.  Examples are provided in square brakets.
 */
function hook_scald_provider() {
  return array(
    'types'         => array(
      'type-slug' => array(                                                                             // Dev
        'title'               => t('Display title for the type. [Image]'),                              // Public
        'description'         => t('A description of the Type. [Image files of most standard types.]'), // Admin
        'description_default' => t('Default description for Atoms of this Type. [A photo or graphic]'), // Public
        'thumbnail_source'    => drupal_get_path('module', 'scald') . '/thumb.jpg',                     // Public (the image itself)
      ),
      // More type slugs with their definition arrays here
    ),

    'atoms'         => array(
      'type-slug' => array(                                   // Dev
        t('Base Entity description. [Drupal Node titles.]'),  // Admin
        // More Base Entity descriptions here
      ),
      // Additional type slugs & Base Entity descriptions arrays here
    ),

    'contexts'      => array(
      'context-slug' => array(                                                                                // Dev
        'title'           => t('Display title for the context. [Editor Representation]'),                     // Admin
        'description'     => t('Description of the context. [What the user sees in the rich-text editor.]'),  // Admin
        'render_language' => 'language-slug',                                                                 // Dev
        'parseable'       => TRUE,                                                                            // Admin
        'formats'         => array(
          'type-slug' => 'format-slug',                                                                       // Dev
          // Additional type-slug/format-slug pairs here
        ),
      ),
      // Additional context slugs & definition arrays here
    ),

    'transcoders'   => array(
      'transcoder-slug' => array(                                                                                     // Dev
        'title'       => t('Display title for the transcoder. [Imagecache Preset X]'),                                // Admin
        'description' => t('Description of transcoder. [Uses the Imagecache Preset to prepare images for display.]'), // Admin
        'formats'     => array(
          'type-slug' => 'format-slug',                                                                               // Dev
          // Additional type-slug/format-slug pairs here
        ),
      ),
      // Additional transcoder slugs & definition arrays here
    ),

    'relationships' => array(
      'relationship-slug' => array(                                                                               // Dev
        'title'         => t('Short relationship descriptor, left-to-right. [includes]'),                         // Public
        'title_reverse' => t('Short relationship descriptor, right-to-left. [is included by]'),                   // Public
        'description'   => t('Description of the nature of the relationship. [When one Atom includes another.]'), // Admin
      ),
      // Additional relationship slug & definition arrays here
    ),

    'actions'       => array(
      'action-slug' => array(                                                                         // Dev
        'title'       => t('Short verb-like action title. [edit]'),                                   // Public
        'description' => t('In-depth description of the action. [Editing the details of an Atom.]'),  // Admin
      ),
      // Additional action slugs & definition arrays here
    ),
  );
}



/**
 * Responds to an Atom's registration by modifying the Atom Object or taking
 *  additional action.
 *
 * @param $atom
 *
 * @param &$values
 *
 * @param $mode
 *
 * @return void
 *  Nothing.  $atom and $values are modified directly.
 */
function hook_scald_register_atom(&$atom, &$values, $mode) {
  switch ($mode) {
    case 'type':
      if (isset($values['foobar'])) {
        // Insert the $atom->sid, $values['foobar'] into a {my_provider_table}

        $atom->foobar = $values['foobar'];
        unset($values['foobar']);
        $values['type-specific-thingie'] = // something of relevance to a later-firing Provider.
      }
      break; // end 'type'

    case 'atom':
      $atom->title = // Some sort of a complicated lookup based on $atom->base_id or something
      break; // end 'atom'

    case 'transcoder':
      $scald_config = variable_get('scald_config', 0);
      // Use the special $values key '@context' (set by Scald Core for each call
      //  of this Hook) to determine the appropriate target format.
      $target_format = $scald_config->contexts[$values['@context']]['type_format'][$atom->type]['file_format']

      // Take $atom->file_source, transcode it, and store it and $atom->sid,
      //  $atom->type, $values['@context'] and anything else necessary in
      //  {my_transcoder_table} (or in the filesystem somewhere).

      unset($values['@context']);
      break; // end 'transcode';

    case 'relationship':
      // Analyze $atom and/or $values and see if any additional entries in
      //  $atom->relationships['forward'] need to be made.  DO NOT write to
      //  {scald_atom_relationships}; Scald Core handles that!
      break; // end 'relationship'

    default:
      return;
      break; // end default
  }
} // end hook_scald_register_atom()



/**
 *
 */
function hook_scald_update_atom(&$atom, &$values, $mode) {

} // end hook_scald_update_atom()



/**
 *
 */
function hook_scald_unregister_atom($atom, $mode) {

} // end hook_scald_unregister_atom()



/**
 *
 */
function hook_scald_fetch($atom, $mode) {
  $atom->description    = 'description';
  $atom->source_file    = 'source path';
  $atom->thumbnail_file = 'thumbnail path';
  $atom->base_entity    = node_load($atom->sid);  // Typically, for Atom Providers which are based on Drupal nodes, the $node object is attached to the $atom as the base_entity member.
} // end hook_scald_fetch()



/**
 *
 */
function hook_scald_prerender(&$atom, $mode) {

} // end hook_scald_prerender()



/**
 *
 */
function hook_scald_render($atom, $mode) {

} // end hook_scald_render()



/**
 *
 */
function hook_scald_rendered_to_sas_LANGUAGE($text) {

} // hook_scald_rendered_to_sas_LANGUAGE()



/**
 *
 */
function hook_scald_action(&$atom, $action, $mode) {

} // end hook_scald_action()

?>


/**
 *
 */
function hook_scald_atom_quickadd() {
  $type = array(
    'type' => 'Image',
    'addpath' => 'node/add/scald_example_content_type',
    'class' => 'scald-child',
  );
  return array($type);
} // end hook_scald_atom_quickadd



4 SCALD HOOK EXECUTION STACK
============================

  The order in which the hooks execute can be fairly important.  Each hook might
add more information to the Atom object or potentially even remove some. Knowing
when a given hook fires relative to others is important.  Note that each hook
will be called for each module that implements it in turn.  The order in which
the module's hooks are called is determined by their relative weight in the
{system} table.

  The following illustrate when each of the various hooks are called relative
to one another.  Keep in mind that there is often prior and intervening code
which could have a significant impact on the contents of $atom or the other
variables being passed to the hooks.

<?php
system_modules_submit() [The form at /admin/build/modules is submitted]
  -> {provider}_install() [Drupal hook]
  -> {provider}_enable() [Drupal hook]
  -> {provider}_scald_provider()
  // @@@TODO: The mass-registration callback
  // @@@TODO: The relationship calculation callback

scald_render()
  -> scald_fetch()
    -> {type_provider}_scald_fetch($mode = 'type')
    -> {atom_provider}_scald_fetch($mode = 'atom')
  -> scald_prerender()
    -> {type_provider}_scald_prerender($mode = 'type')
    -> {atom_provider}_scald_prerender($mode = 'atom')
    -> {transcoder_provider}_scald_prerender($mode = 'transcoder')
    -> {context_provider}_scald_prerender($mode = 'context')
  -> {context_provider}_scald_render()

scald_register_atom(), scald_update_atom(), scald_unregister_atom()
  -> {type_provider}_scald_fetch($mode = 'type')
  -> {atom_provider}_scald_fetch($mode = 'atom')
  -> {relationship_provider}_scald_prerender($mode = 'relationship')
  -> {transcoder_provider}_scald_prerender($mode = 'transcoder')

scald_rendered_to_sas()
  -> scald_rendered_to_sas_LANGUAGE()
?>

File

docs/scald_provider_api.txt
View source
  1. Scald Provider API Documentation
  2. ================================================================================
  3. Scald Core Version: 0.7
  4. Documentation Updated: 2009-05-05
  5. NOTE: For a general understanding of Scald's architecture, definitions of
  6. various terms, or additional information about the use of Scald, please
  7. reference docs/scald_overview.txt
  8. Contents
  9. --------
  10. 1 Conventions
  11. 2 Scald Hooks
  12. 3 Scald Hook Example Implementations
  13. 4 Scald Hook Execution Stack
  14. 1 CONVENTIONS
  15. =============
  16. Throughout this spec, various parameters or members will be marked as
  17. "Public", "Admin", or "Dev" (for instance the display title of the Unified
  18. Type). Anything which is marked as "Public" will be visible to the average User
  19. of Scald. Most items marked "Public" are also configurable by Admins (e.g. your
  20. "Really cool" Unified Type might get overriden to "Really stupid" in the Admin
  21. interface). Finally, items marked "Dev" are not explicitly intended for display
  22. to Admins or the Public.
  23. 2 SCALD HOOKS
  24. =============
  25. Below are the function declarations for all Scald Core hooks grouped by Scald
  26. Provider type. Hooks which are common to multiple types are listed in each
  27. section. See "SCALD CORE HOOK EXAMPLE IMPLEMENTATIONS" for specifics about each
  28. hook. For hooks with the $mode parameter, $mode will be one of: type, atom,
  29. context, transcoder, relationship, action.
  30. // Type Provider Hooks
  31. function hook_scald_provider();
  32. function hook_scald_register_atom(&$atom, &$values, $mode);
  33. function hook_scald_update_atom(&$atom, &$values, $mode);
  34. function hook_scald_unregister_atom($atom, $mode);
  35. function hook_scald_fetch(&$atom, $mode);
  36. function hook_scald_prerender(&$atom, $mode);
  37. // Atom Provider Hooks
  38. function hook_scald_provider();
  39. function hook_scald_register_atom(&$atom, &$values $mode);
  40. function hook_scald_update_atom(&$atom, &$values, $mode);
  41. function hook_scald_unregister_atom($atom, $mode);
  42. function hook_scald_fetch(&$atom, $mode);
  43. function hook_scald_prerender(&$atom, $mode);
  44. function hook_scald_action(&$atom, $action, $mode);
  45. // Context Provider Hooks
  46. function hook_scald_provider();
  47. function hook_scald_prerender(&$atom, $context, $options, $mode);
  48. function hook_scald_render($atom, $context, $options);
  49. function hook_scald_rendered_to_sas_LANGUAGE($text);
  50. // Transcoder Provider Hooks
  51. function hook_scald_provider();
  52. function hook_scald_register_atom($atom, &$values, $mode);
  53. function hook_scald_update_atom($atom, &$values, $mode);
  54. function hook_scald_unregister_atom($atom, $mode);
  55. function hook_scald_prerender(&$atom, $mode);
  56. // Relationship Provider Hooks
  57. function hook_scald_provider();
  58. function hook_scald_register_atom(&$atom, &$values, $mode);
  59. function hook_scald_update_atom(&$atom, &$values, $mode);
  60. function hook_scald_unregister_atom($atom, $mode);
  61. // Action Provider Hooks
  62. function hook_scald_provider();
  63. function hook_scald_action(&$atom, $action, $mode);
  64. // Quick links
  65. function hook_scald_atom_quickadd();
  66. ?>
  67. 3 SCALD HOOK EXAMPLE IMPLEMENTATIONS
  68. ====================================
  69. Below are sample implementations for each of the Scald Core hooks. Hooks
  70. which might be implemented by more than one type of Scald Provider are shown
  71. as if the implementing module advertised each possible type of Scald Provider.
  72. /**
  73. * Advertise what Scald Providers this module implements to Scald Core.
  74. *
  75. * A module can define zero or more Scald Providers of each Provider Type (more
  76. * than one slug/definition array can be included in each provider-type array).
  77. *
  78. * NOTE: Scald Context Providers: specifying formats for types is
  79. * only necessary if the Context is going to do something specific with the
  80. * data included in Scald Atoms of that type. If no format is specified for
  81. * a given type by default, one can be specified in the Admin interface, but
  82. * it is not required. In fact, it is discouraged because the more formats
  83. * that are specified for Scald Contexts, the more work the Transcoders need
  84. * to do.
  85. *
  86. * @return
  87. * A structured array which includes the required data for the Provisions
  88. * provided by the Scald Provider. The array takes the format indicated
  89. * below. Examples are provided in square brakets.
  90. */
  91. function hook_scald_provider() {
  92. return array(
  93. 'types' => array(
  94. 'type-slug' => array( // Dev
  95. 'title' => t('Display title for the type. [Image]'), // Public
  96. 'description' => t('A description of the Type. [Image files of most standard types.]'), // Admin
  97. 'description_default' => t('Default description for Atoms of this Type. [A photo or graphic]'), // Public
  98. 'thumbnail_source' => drupal_get_path('module', 'scald') . '/thumb.jpg', // Public (the image itself)
  99. ),
  100. // More type slugs with their definition arrays here
  101. ),
  102. 'atoms' => array(
  103. 'type-slug' => array( // Dev
  104. t('Base Entity description. [Drupal Node titles.]'), // Admin
  105. // More Base Entity descriptions here
  106. ),
  107. // Additional type slugs & Base Entity descriptions arrays here
  108. ),
  109. 'contexts' => array(
  110. 'context-slug' => array( // Dev
  111. 'title' => t('Display title for the context. [Editor Representation]'), // Admin
  112. 'description' => t('Description of the context. [What the user sees in the rich-text editor.]'), // Admin
  113. 'render_language' => 'language-slug', // Dev
  114. 'parseable' => TRUE, // Admin
  115. 'formats' => array(
  116. 'type-slug' => 'format-slug', // Dev
  117. // Additional type-slug/format-slug pairs here
  118. ),
  119. ),
  120. // Additional context slugs & definition arrays here
  121. ),
  122. 'transcoders' => array(
  123. 'transcoder-slug' => array( // Dev
  124. 'title' => t('Display title for the transcoder. [Imagecache Preset X]'), // Admin
  125. 'description' => t('Description of transcoder. [Uses the Imagecache Preset to prepare images for display.]'), // Admin
  126. 'formats' => array(
  127. 'type-slug' => 'format-slug', // Dev
  128. // Additional type-slug/format-slug pairs here
  129. ),
  130. ),
  131. // Additional transcoder slugs & definition arrays here
  132. ),
  133. 'relationships' => array(
  134. 'relationship-slug' => array( // Dev
  135. 'title' => t('Short relationship descriptor, left-to-right. [includes]'), // Public
  136. 'title_reverse' => t('Short relationship descriptor, right-to-left. [is included by]'), // Public
  137. 'description' => t('Description of the nature of the relationship. [When one Atom includes another.]'), // Admin
  138. ),
  139. // Additional relationship slug & definition arrays here
  140. ),
  141. 'actions' => array(
  142. 'action-slug' => array( // Dev
  143. 'title' => t('Short verb-like action title. [edit]'), // Public
  144. 'description' => t('In-depth description of the action. [Editing the details of an Atom.]'), // Admin
  145. ),
  146. // Additional action slugs & definition arrays here
  147. ),
  148. );
  149. }
  150. /**
  151. * Responds to an Atom's registration by modifying the Atom Object or taking
  152. * additional action.
  153. *
  154. * @param $atom
  155. *
  156. * @param &$values
  157. *
  158. * @param $mode
  159. *
  160. * @return void
  161. * Nothing. $atom and $values are modified directly.
  162. */
  163. function hook_scald_register_atom(&$atom, &$values, $mode) {
  164. switch ($mode) {
  165. case 'type':
  166. if (isset($values['foobar'])) {
  167. // Insert the $atom->sid, $values['foobar'] into a {my_provider_table}
  168. $atom->foobar = $values['foobar'];
  169. unset($values['foobar']);
  170. $values['type-specific-thingie'] = // something of relevance to a later-firing Provider.
  171. }
  172. break; // end 'type'
  173. case 'atom':
  174. $atom->title = // Some sort of a complicated lookup based on $atom->base_id or something
  175. break; // end 'atom'
  176. case 'transcoder':
  177. $scald_config = variable_get('scald_config', 0);
  178. // Use the special $values key '@context' (set by Scald Core for each call
  179. // of this Hook) to determine the appropriate target format.
  180. $target_format = $scald_config->contexts[$values['@context']]['type_format'][$atom->type]['file_format']
  181. // Take $atom->file_source, transcode it, and store it and $atom->sid,
  182. // $atom->type, $values['@context'] and anything else necessary in
  183. // {my_transcoder_table} (or in the filesystem somewhere).
  184. unset($values['@context']);
  185. break; // end 'transcode';
  186. case 'relationship':
  187. // Analyze $atom and/or $values and see if any additional entries in
  188. // $atom->relationships['forward'] need to be made. DO NOT write to
  189. // {scald_atom_relationships}; Scald Core handles that!
  190. break; // end 'relationship'
  191. default:
  192. return;
  193. break; // end default
  194. }
  195. } // end hook_scald_register_atom()
  196. /**
  197. *
  198. */
  199. function hook_scald_update_atom(&$atom, &$values, $mode) {
  200. } // end hook_scald_update_atom()
  201. /**
  202. *
  203. */
  204. function hook_scald_unregister_atom($atom, $mode) {
  205. } // end hook_scald_unregister_atom()
  206. /**
  207. *
  208. */
  209. function hook_scald_fetch($atom, $mode) {
  210. $atom->description = 'description';
  211. $atom->source_file = 'source path';
  212. $atom->thumbnail_file = 'thumbnail path';
  213. $atom->base_entity = node_load($atom->sid); // Typically, for Atom Providers which are based on Drupal nodes, the $node object is attached to the $atom as the base_entity member.
  214. } // end hook_scald_fetch()
  215. /**
  216. *
  217. */
  218. function hook_scald_prerender(&$atom, $mode) {
  219. } // end hook_scald_prerender()
  220. /**
  221. *
  222. */
  223. function hook_scald_render($atom, $mode) {
  224. } // end hook_scald_render()
  225. /**
  226. *
  227. */
  228. function hook_scald_rendered_to_sas_LANGUAGE($text) {
  229. } // hook_scald_rendered_to_sas_LANGUAGE()
  230. /**
  231. *
  232. */
  233. function hook_scald_action(&$atom, $action, $mode) {
  234. } // end hook_scald_action()
  235. ?>
  236. /**
  237. *
  238. */
  239. function hook_scald_atom_quickadd() {
  240. $type = array(
  241. 'type' => 'Image',
  242. 'addpath' => 'node/add/scald_example_content_type',
  243. 'class' => 'scald-child',
  244. );
  245. return array($type);
  246. } // end hook_scald_atom_quickadd
  247. 4 SCALD HOOK EXECUTION STACK
  248. ============================
  249. The order in which the hooks execute can be fairly important. Each hook might
  250. add more information to the Atom object or potentially even remove some. Knowing
  251. when a given hook fires relative to others is important. Note that each hook
  252. will be called for each module that implements it in turn. The order in which
  253. the module's hooks are called is determined by their relative weight in the
  254. {system} table.
  255. The following illustrate when each of the various hooks are called relative
  256. to one another. Keep in mind that there is often prior and intervening code
  257. which could have a significant impact on the contents of $atom or the other
  258. variables being passed to the hooks.
  259. system_modules_submit() [The form at /admin/build/modules is submitted]
  260. -> {provider}_install() [Drupal hook]
  261. -> {provider}_enable() [Drupal hook]
  262. -> {provider}_scald_provider()
  263. // @@@TODO: The mass-registration callback
  264. // @@@TODO: The relationship calculation callback
  265. scald_render()
  266. -> scald_fetch()
  267. -> {type_provider}_scald_fetch($mode = 'type')
  268. -> {atom_provider}_scald_fetch($mode = 'atom')
  269. -> scald_prerender()
  270. -> {type_provider}_scald_prerender($mode = 'type')
  271. -> {atom_provider}_scald_prerender($mode = 'atom')
  272. -> {transcoder_provider}_scald_prerender($mode = 'transcoder')
  273. -> {context_provider}_scald_prerender($mode = 'context')
  274. -> {context_provider}_scald_render()
  275. scald_register_atom(), scald_update_atom(), scald_unregister_atom()
  276. -> {type_provider}_scald_fetch($mode = 'type')
  277. -> {atom_provider}_scald_fetch($mode = 'atom')
  278. -> {relationship_provider}_scald_prerender($mode = 'relationship')
  279. -> {transcoder_provider}_scald_prerender($mode = 'transcoder')
  280. scald_rendered_to_sas()
  281. -> scald_rendered_to_sas_LANGUAGE()
  282. ?>