media.api.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * @file
  4. * Hook provided by the media module.
  5. */
  6. /**
  7. * Return an array of plugins for the media browser.
  8. *
  9. * Implementors are expected to return a renderable element.
  10. *
  11. * Each element will be a jQuery tab on the media browser.
  12. *
  13. * Some elements are special:
  14. * - #title: The title that goes on the tab
  15. * - #settings: Drupal.settings.media.browser.$key (where key is the array key).
  16. * - #callback: If provided, will make the tab an "ajax" tab.
  17. *
  18. * Example:
  19. * $plugins['library'] = array(
  20. * '#title' => t('Library'),
  21. * '#attached' => array(
  22. * 'js' => array(
  23. * $path . '/js/plugins/media.library.js',
  24. * ),
  25. * ),
  26. * '#settings' => array(
  27. * 'viewMode' => 'thumbnails',
  28. * 'getMediaUrl' => url('media/browser/list'),
  29. * ),
  30. * '#markup' => '<div> Library goes here</div>',
  31. * );
  32. *
  33. * @param $plugin_name
  34. * The name of the plugin to view
  35. *
  36. * @param $params
  37. * An array of parameters which came in is $_GET['params'].
  38. * The expected parameters is still being defined.
  39. * - types: Array of media types to support
  40. * - multiselect: Boolean enabling or disabling multiselect
  41. *
  42. * @return
  43. * Renderable array.
  44. */
  45. function hook_media_browser_plugin_view($plugin_name, $params) {
  46. }
  47. /**
  48. * Returns a list of plugins for the media browser.
  49. *
  50. * Plugins are defined in a multi-dimensional associative
  51. * array format with the following keys:
  52. *
  53. * - #weight (optional): Weight of the plugin in relation to other plugins
  54. * when being displayed, e.g. tabs in the browser.
  55. *
  56. * @example
  57. * <code>
  58. * array(
  59. * 'unique_plugin_name' => array(
  60. * '#weight' => 42,
  61. * ),
  62. * );
  63. * </code>
  64. */
  65. function hook_media_browser_plugin_info() {
  66. }
  67. /**
  68. * Returns an array of operations which can be taken on media items.
  69. *
  70. * This is used on the admin/content/media page so users can select multiple
  71. * items and do something with them.
  72. *
  73. * The return format is an array or arrays with the following keys:
  74. * - label: The string to be shown to the user.
  75. * - callback (optional): A callback to be called when the media items are selected.
  76. * Media items will be passed in as an argument.
  77. * - redirect (optional): A path to redirect to. %fids should be in the path
  78. * It will be replaced with the fids selected delimited by "+".
  79. * i.e. mymodule/%fids/something -> mymodule/1+3+2/something if media items
  80. * 1, 3 and 2 were selected.
  81. */
  82. function media_media_operations() {
  83. }
  84. /**
  85. * Alter the output generated by Media filter tags.
  86. *
  87. * @param array &$element
  88. * The renderable array of output generated for the filter tag.
  89. * @param array $tag
  90. * The filter tag converted into an associative array by
  91. * media_token_to_markup() with the following elements:
  92. * - 'fid': The ID of the media file being rendered.
  93. * - 'file': The object from file_load() of the media file being rendered.
  94. * - 'view_mode': The view mode being used to render the file.
  95. * - 'attributes': An additional array of attributes that could be output
  96. * with media_get_file_without_label().
  97. * @param array $settings
  98. * An additional array of settings.
  99. * - 'wysiwyg': A boolean if the output is for the WYSIWYG preview or FALSE
  100. * if for normal rendering.
  101. */
  102. function hook_media_token_to_markup_alter(array &$element, array $tag, array $settings) {
  103. if (empty($settings['wysiwyg'])) {
  104. $element['#attributes']['alt'] = t('This media has been output using the @mode view mode.', array('@mode' => $tag['view_mode']));
  105. }
  106. }