video_embed_field.api.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * API Info for video_embed_field module
  4. */
  5. /**
  6. * @function hook_video_embed_handler_info
  7. * Can be used to add more handlers for video_embed_field
  8. * @return an array of handlers, each handler is an array with the following
  9. * keys:
  10. * 'title' : required, the untranslated title of the provider, to show to the
  11. * admin user.
  12. * 'function' : required, the function used to generate the embed code.
  13. * 'thumbnail_function' : optional, the function used to provide the thumbnail
  14. * for a video.
  15. * 'thumbnail_default : optional, the default thumbnail image to display in case
  16. * thumbnail_function does not exist or has no results.
  17. * 'data_function' : optional, the function to return an array of video data.
  18. * 'form' : required, the function that returns the settings form for your
  19. * provider.
  20. * 'form_validate: optional the function that validates the settings form for
  21. * your provider.
  22. * 'domains' : required, an array of domains to match against, this is used to
  23. * know which provider to use.
  24. * 'defaults' : default values for each setting made configurable in your form
  25. * function.
  26. *
  27. * @see hook_video_embed_handler_info_alter()
  28. * @see below for function definitions
  29. */
  30. function hook_video_embed_handler_info() {
  31. $handlers = array();
  32. $handlers['ustream'] = array(
  33. 'title' => 'UStream',
  34. 'function' => 'your_module_handle_ustream',
  35. 'thumbnail_function' => 'your_module_handle_ustream_thumbnail',
  36. 'thumbnail_default' => drupal_get_path('module', 'your_module') . '/img/ustream.jpg',
  37. 'data_function' => 'your_module_handler_ustream_data',
  38. 'form' => 'your_module_handler_ustream_form',
  39. 'form_validate' => 'your_module_handler_ustream_form_validate',
  40. 'domains' => array(
  41. 'ustream.com',
  42. ),
  43. 'defaults' => array(
  44. 'width' => 640,
  45. 'height' => 360,
  46. ),
  47. );
  48. return $handlers;
  49. }
  50. /**
  51. * Performs alterations on video_embed_field handlers.
  52. *
  53. * @param $info
  54. * Array of information on video handlers exposed by
  55. * hook_video_embed_handler_info() implementations.
  56. */
  57. function hook_video_embed_handler_info_alter(&$info) {
  58. // Change the thumbnail function for 'ustream' provider.
  59. if (isset($info['ustream'])) {
  60. $info['ustream']['thumbnail_function'] = 'your_module_handle_ustream_thumbnail_alter';
  61. }
  62. }
  63. /**
  64. * Example callbacks for a provider (in this case for ustream).
  65. * Obviously, these functions are only for example purposes.
  66. */
  67. /**
  68. * Generate the embed code for a video
  69. * @param $url - the video url as entered by the user
  70. * @param $settings - the settings for this provider as defined in the form function,
  71. * defaulting to your provider's defaults
  72. * @return the embed code as a renderable array
  73. */
  74. function your_module_handle_ustream($url, $settings) {
  75. return array(
  76. //this should be the full embed code for your provider, including each of the settings
  77. '#markup' => '<iframe src="ustream"></iframe>',
  78. );
  79. }
  80. /**
  81. * Retrieve information about the thumbnail for a given url
  82. * @param $url - the url of the video as entered by the user
  83. * @return an array with the keys:
  84. * 'id' => an id for the video which is unique to your provider, used for naming the cached thumbnail file
  85. * 'url' => the url to retrieve the thumbnail from
  86. */
  87. function your_module_handle_ustream_thumbnail($url) {
  88. return array(
  89. 'id' => '12332243242', //generally the id that the provider uses for the video
  90. 'url' => 'http://something/thumbnail/somthing.jpg', //the url of the thumbnail
  91. );
  92. }
  93. /**
  94. * A forms api callback, returns the settings form for the provider
  95. * @param $defaults - default/current values for your provider, the currently saved settings
  96. * with empty values filled with the defaults provided in info hook
  97. * @return a form as defined by forms api
  98. *
  99. * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7
  100. */
  101. function your_module_handler_ustream_form($defaults) {
  102. $form = array();
  103. $form['width'] = array(
  104. '#type' => 'textfield',
  105. '#title' => t('Player Width'),
  106. '#description' => t('The width of the player in pixels'),
  107. '#default_value' => $defaults['width'],
  108. );
  109. return $form;
  110. }
  111. /**
  112. * Return an array of extra data to be stored with the video, this data will be available for theming
  113. * @return an array
  114. */
  115. function your_module_handler_ustream_data($url) {
  116. return array();
  117. }