media.api.php

  1. cis7 sites/all/modules/ulmus/media/media.api.php
  2. cle7 sites/all/modules/ulmus/media/media.api.php
  3. ecd7 sites/all/modules/ulmus/media/media.api.php
  4. elmsmedia7 sites/all/modules/ulmus/media/media.api.php
  5. harmony7 sites/all/modules/ulmus/media/media.api.php
  6. icor7 sites/all/modules/ulmus/media/media.api.php
  7. meedjum_blog7 sites/all/modules/ulmus/media/media.api.php
  8. mooc7 sites/all/modules/ulmus/media/media.api.php

Hooks provided by the Media module.

Functions

Namesort descending Description
hook_media_browser_params_alter Alter a singleton of the params passed to the media browser.
hook_media_browser_plugins_alter Alter the plugins before they are rendered.
hook_media_browser_plugin_info Returns a list of plugins for the media browser.
hook_media_browser_plugin_info_alter Alter the list of plugins for the media browser.
hook_media_format_form_prepare_alter Alter the WYSIWYG view mode selection form.
hook_media_parse Parses a url or embedded code into a unique URI.
hook_media_token_to_markup_alter Alter the output generated by Media filter tags.
hook_media_wysiwyg_allowed_view_modes_alter Alter a list of view modes allowed for a file embedded in the WYSIWYG.

File

sites/all/modules/ulmus/media/media.api.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Hooks provided by the Media module.
  5. */
  6. /**
  7. * Parses a url or embedded code into a unique URI.
  8. *
  9. * @param string $url
  10. * The original URL or embed code to parse.
  11. *
  12. * @return array
  13. * The unique URI for the file, based on its stream wrapper, or NULL.
  14. *
  15. * @see media_parse_to_file()
  16. * @see media_add_from_url_validate()
  17. */
  18. function hook_media_parse($url) {
  19. // Only parse URLs from our website of choice: examplevideo.com
  20. if (substr($url, 0, 27) == 'http://www.examplevideo.com') {
  21. // Each video has a 5 digit ID, i.e. http://www.examplevideo.com/12345
  22. // Grab the ID and use it in our URI.
  23. $id = substr($url, 28, 33);
  24. return file_stream_wrapper_uri_normalize('examplevideo://video/' . $id);
  25. }
  26. }
  27. /**
  28. * Returns a list of plugins for the media browser.
  29. *
  30. * @return array
  31. * A nested array of plugin information, keyed by plugin name. Each plugin
  32. * info array may have the following keys:
  33. * - title: (required) A name for the tab in the media browser.
  34. * - class: (required) The class name of the handler. This class must
  35. * implement a view() method, and may (should) extend the
  36. * @link MediaBrowserPlugin MediaBrowserPlugin @endlink class.
  37. * - weight: (optional) Integer to determine the tab order. Defaults to 0.
  38. * - access callback: (optional) A callback for user access checks.
  39. * - access arguments: (optional) An array of arguments for the user access
  40. * check.
  41. *
  42. * Additional custom keys may be provided for use by the handler.
  43. *
  44. * @see hook_media_browser_plugin_info_alter()
  45. * @see media_get_browser_plugin_info()
  46. */
  47. function hook_media_browser_plugin_info() {
  48. $info['media_upload'] = array(
  49. 'title' => t('Upload'),
  50. 'class' => 'MediaBrowserUpload',
  51. 'weight' => -10,
  52. 'access callback' => 'user_access',
  53. 'access arguments' => array('create files'),
  54. );
  55. return $info;
  56. }
  57. /**
  58. * Alter the list of plugins for the media browser.
  59. *
  60. * @param array $info
  61. * The associative array of media browser plugin definitions from
  62. * hook_media_browser_plugin_info().
  63. *
  64. * @see hook_media_browser_plugin_info()
  65. * @see media_get_browser_plugin_info()
  66. */
  67. function hook_media_browser_plugin_info_alter(&$info) {
  68. $info['media_upload']['title'] = t('Upload 2.0');
  69. $info['media_upload']['class'] = 'MediaBrowserUploadImproved';
  70. }
  71. /**
  72. * Alter the plugins before they are rendered.
  73. *
  74. * @param array $plugin_output
  75. * The associative array of media browser plugin information from
  76. * media_get_browser_plugin_info().
  77. *
  78. * @see hook_media_browser_plugin_info()
  79. * @see media_get_browser_plugin_info()
  80. */
  81. function hook_media_browser_plugins_alter(&$plugin_output) {
  82. $plugin_output['upload']['form']['upload']['#title'] = t('Upload 2.0');
  83. $plugin_output['media_internet']['form']['embed_code']['#size'] = 100;
  84. }
  85. /**
  86. * Alter a singleton of the params passed to the media browser.
  87. *
  88. * @param array $stored_params
  89. * An array of parameters provided when a media_browser is launched.
  90. *
  91. * @see media_browser()
  92. * @see media_set_browser_params()
  93. */
  94. function hook_media_browser_params_alter(&$stored_params) {
  95. $stored_params['types'][] = 'document';
  96. unset($stored_params['enabledPlugins'][0]);
  97. }
  98. /**
  99. * Alter a list of view modes allowed for a file embedded in the WYSIWYG.
  100. *
  101. * @param array $view_modes
  102. * An array of view modes that can be used on the file when embedded in the
  103. * WYSIWYG.
  104. * @param object $file
  105. * A file entity.
  106. *
  107. * @see media_get_wysiwyg_allowed_view_modes()
  108. */
  109. function hook_media_wysiwyg_allowed_view_modes_alter(&$view_modes, $file) {
  110. $view_modes['default']['label'] = t('Display an unmodified version of the file');
  111. unset($view_modes['preview']);
  112. }
  113. /**
  114. * Alter the WYSIWYG view mode selection form.
  115. *
  116. * Similar to a form_alter, but runs first so that modules can add
  117. * fields specific to a given file type (like alt tags on images) before alters
  118. * begin to work on the fields.
  119. *
  120. * @param array $form
  121. * An associative array containing the structure of the form.
  122. * @param array $form_state
  123. * An associative array containing the current state of the form.
  124. * @param object $file
  125. * A file entity.
  126. *
  127. * @see media_format_form()
  128. */
  129. function hook_media_format_form_prepare_alter(&$form, &$form_state, $file) {
  130. $form['preview']['#access'] = FALSE;
  131. $file = $form['#media'];
  132. $form['heading']['#markup'] = t('Embedding %filename of type %filetype', array('%filename' => $file->filename, '%filetype' => $file->type));
  133. }
  134. /**
  135. * Alter the output generated by Media filter tags.
  136. *
  137. * @param array $element
  138. * The renderable array of output generated for the filter tag.
  139. * @param array $tag_info
  140. * The filter tag converted into an associative array by
  141. * media_token_to_markup() with the following elements:
  142. * - 'fid': The ID of the media file being rendered.
  143. * - 'file': The object from file_load() of the media file being rendered.
  144. * - 'view_mode': The view mode being used to render the file.
  145. * - 'attributes': An additional array of attributes that could be output
  146. * with media_get_file_without_label().
  147. * @param array $settings
  148. * An additional array of settings.
  149. * - 'wysiwyg': A boolean if the output is for the WYSIWYG preview or FALSE
  150. * if for normal rendering.
  151. *
  152. * @see media_token_to_markup()
  153. */
  154. function hook_media_token_to_markup_alter(&$element, $tag_info, $settings) {
  155. if (empty($settings['wysiwyg'])) {
  156. $element['#attributes']['alt'] = t('This media has been output using the @mode view mode.', array('@mode' => $tag_info['view_mode']));
  157. }
  158. }