media_library.api.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * @file
  4. * Documentation related to Media Library.
  5. */
  6. /**
  7. * @defgroup media_library_architecture Media Library Architecture
  8. * @{
  9. *
  10. * Media Library is a UI for the core Media module. It provides a visual
  11. * interface for users to manage media in their site, and it allows authors to
  12. * visually select media for use in entity reference and text fields, using a
  13. * modal dialog.
  14. *
  15. * In order to provide a consistent user experience, Media Library is
  16. * intentionally opinionated, with few extension points and no hooks. Most of
  17. * its code is internal and should not be extended or instantiated by external
  18. * code.
  19. *
  20. * @section openers Openers
  21. * Interaction with the modal media library dialog is mediated by "opener"
  22. * services. All openers must implement
  23. * \Drupal\media_library\MediaLibraryOpenerInterface.
  24. *
  25. * Openers are responsible for determining access to the media library, and for
  26. * generating an AJAX response when the user has finished selecting media items
  27. * in the library. An opener is a "bridge" between the opinionated media library
  28. * modal dialog and whatever is consuming it, allowing the dialog to be
  29. * triggered in a way that makes sense for that particular consumer. Examples in
  30. * Drupal core include entity reference fields and text editors.
  31. *
  32. * @see \Drupal\media_library\MediaLibraryOpenerInterface
  33. * @see \Drupal\media_library\MediaLibraryEditorOpener
  34. * @see \Drupal\media_library\MediaLibraryFieldWidgetOpener
  35. *
  36. * @section state Modal dialog state
  37. * When the media library modal is used, its configuration and state (such as
  38. * how many items are currently selected, the maximum number that can be
  39. * selected, which media types the user is allowed to see, and so forth) are
  40. * stored in an instance of \Drupal\media_library\MediaLibraryState. The state
  41. * object also stores the service ID of the opener being used, as well as any
  42. * additional parameters or data that are specific to that opener.
  43. *
  44. * The media library state is passed between the user and the server in the
  45. * URL's query parameters. Therefore, the state is also protected by a hash in
  46. * order to prevent tampering.
  47. *
  48. * @see \Drupal\media_library\MediaLibraryState
  49. *
  50. * @section add_form Adding media in the dialog
  51. * Users with appropriate permissions can add media to the library from directly
  52. * within the modal dialog.
  53. *
  54. * This interaction is implemented using forms, and is customizable by modules.
  55. * Since the media library is segmented by media type, each media type can
  56. * expose a different form for adding media of that type; the type's source
  57. * plugin specifies the actual form class to use. Here is an example of a media
  58. * source plugin definition which provides an add form for the media library:
  59. *
  60. * @code
  61. * @MediaSource(
  62. * id = "file",
  63. * label = @Translation("File"),
  64. * description = @Translation("Use local files for reusable media."),
  65. * allowed_field_types = {"file"},
  66. * default_thumbnail_filename = "generic.png",
  67. * forms = {
  68. * "media_library_add" = "\Drupal\media_library\Form\FileUploadForm",
  69. * },
  70. * )
  71. * @endcode
  72. *
  73. * This can also be done in hook_media_source_info_alter(). For example:
  74. *
  75. * @code
  76. * function example_media_source_info_alter(array &$sources) {
  77. * $sources['file']['forms']['media_library_add'] = "\Drupal\media_library\Form\FileUploadForm";
  78. * }
  79. * @endcode
  80. *
  81. * The add form is a standard form class, and can be altered by modules and
  82. * themes just like any other form. For easier implementation, it is recommended
  83. * that modules extend \Drupal\media_library\Form\AddFormBase when providing add
  84. * forms.
  85. *
  86. * @see \Drupal\media_library\Form\AddFormBase
  87. * @see \Drupal\media_library\Form\FileUploadForm
  88. * @see \Drupal\media_library\Form\OEmbedForm
  89. *
  90. * @}
  91. */