media_library.install 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the media_library module.
  5. */
  6. use Drupal\media\Entity\MediaType;
  7. /**
  8. * Implements hook_install().
  9. */
  10. function media_library_install($is_syncing) {
  11. if (!$is_syncing) {
  12. foreach (MediaType::loadMultiple() as $type) {
  13. _media_library_configure_form_display($type);
  14. _media_library_configure_view_display($type);
  15. }
  16. }
  17. }
  18. /**
  19. * Create the 'media_library' image style.
  20. */
  21. function media_library_update_8701() {
  22. // This update function has been moved to
  23. // media_library_post_update_add_media_library_image_style().
  24. }
  25. /**
  26. * Updates the media library view widget display (contextual) filters.
  27. */
  28. function media_library_update_8702() {
  29. $view = \Drupal::configFactory()->getEditable('views.view.media_library');
  30. if ($view && $view->get('display.widget')) {
  31. $view->set('display.widget.display_options.defaults.filters', FALSE);
  32. $view->set('display.widget.display_options.defaults.filter_groups', FALSE);
  33. $view->set('display.widget.display_options.defaults.arguments', FALSE);
  34. $view->set('display.widget.display_options.filters', [
  35. 'status' => [
  36. 'id' => 'status',
  37. 'table' => 'media_field_data',
  38. 'field' => 'status',
  39. 'relationship' => 'none',
  40. 'group_type' => 'group',
  41. 'admin_label' => '',
  42. 'operator' => '=',
  43. 'value' => '1',
  44. 'group' => 1,
  45. 'exposed' => FALSE,
  46. 'expose' => [
  47. 'operator_id' => '',
  48. 'label' => '',
  49. 'description' => '',
  50. 'use_operator' => FALSE,
  51. 'operator' => '',
  52. 'identifier' => '',
  53. 'required' => FALSE,
  54. 'remember' => FALSE,
  55. 'multiple' => FALSE,
  56. 'remember_roles' => [
  57. 'authenticated' => 'authenticated',
  58. ],
  59. ],
  60. 'is_grouped' => FALSE,
  61. 'group_info' => [
  62. 'label' => '',
  63. 'description' => '',
  64. 'identifier' => '',
  65. 'optional' => TRUE,
  66. 'widget' => 'select',
  67. 'multiple' => FALSE,
  68. 'remember' => FALSE,
  69. 'default_group' => 'All',
  70. 'default_group_multiple' => [],
  71. 'group_items' => [],
  72. ],
  73. 'entity_type' => 'media',
  74. 'entity_field' => 'status',
  75. 'plugin_id' => 'boolean',
  76. ],
  77. 'name' => [
  78. 'id' => 'name',
  79. 'table' => 'media_field_data',
  80. 'field' => 'name',
  81. 'relationship' => 'none',
  82. 'group_type' => 'group',
  83. 'admin_label' => '',
  84. 'operator' => 'contains',
  85. 'value' => '',
  86. 'group' => 1,
  87. 'exposed' => TRUE,
  88. 'expose' => [
  89. 'operator_id' => 'name_op',
  90. 'label' => 'Name',
  91. 'description' => '',
  92. 'use_operator' => FALSE,
  93. 'operator' => 'name_op',
  94. 'identifier' => 'name',
  95. 'required' => FALSE,
  96. 'remember' => FALSE,
  97. 'multiple' => FALSE,
  98. 'remember_roles' => [
  99. 'authenticated' => 'authenticated',
  100. 'anonymous' => '0',
  101. 'administrator' => '0',
  102. ],
  103. ],
  104. 'is_grouped' => FALSE,
  105. 'group_info' => [
  106. 'label' => '',
  107. 'description' => '',
  108. 'identifier' => '',
  109. 'optional' => TRUE,
  110. 'widget' => 'select',
  111. 'multiple' => FALSE,
  112. 'remember' => FALSE,
  113. 'default_group' => 'All',
  114. 'default_group_multiple' => [],
  115. 'group_items' => [],
  116. ],
  117. 'entity_type' => 'media',
  118. 'entity_field' => 'name',
  119. 'plugin_id' => 'string',
  120. ],
  121. ]);
  122. $view->set('display.widget.display_options.filter_groups', [
  123. 'operator' => 'AND',
  124. 'groups' => [
  125. 1 => 'AND',
  126. ],
  127. ]);
  128. $view->set('display.widget.display_options.arguments', [
  129. 'bundle' => [
  130. 'id' => 'bundle',
  131. 'table' => 'media_field_data',
  132. 'field' => 'bundle',
  133. 'relationship' => 'none',
  134. 'group_type' => 'group',
  135. 'admin_label' => '',
  136. 'default_action' => 'ignore',
  137. 'exception' => [
  138. 'value' => 'all',
  139. 'title_enable' => FALSE,
  140. 'title' => 'All',
  141. ],
  142. 'title_enable' => FALSE,
  143. 'title' => '',
  144. 'default_argument_type' => 'fixed',
  145. 'default_argument_options' => [
  146. 'argument' => '',
  147. ],
  148. 'default_argument_skip_url' => FALSE,
  149. 'summary_options' => [
  150. 'base_path' => '',
  151. 'count' => TRUE,
  152. 'items_per_page' => 25,
  153. 'override' => FALSE,
  154. ],
  155. 'summary' => [
  156. 'sort_order' => 'asc',
  157. 'number_of_records' => 0,
  158. 'format' => 'default_summary',
  159. ],
  160. 'specify_validation' => FALSE,
  161. 'validate' => [
  162. 'type' => 'none',
  163. 'fail' => 'not found',
  164. ],
  165. 'validate_options' => [],
  166. 'glossary' => FALSE,
  167. 'limit' => 0,
  168. 'case' => 'none',
  169. 'path_case' => 'none',
  170. 'transform_dash' => FALSE,
  171. 'break_phrase' => FALSE,
  172. 'entity_type' => 'media',
  173. 'entity_field' => 'bundle',
  174. 'plugin_id' => 'string',
  175. ],
  176. ]);
  177. $view->save(TRUE);
  178. }
  179. }
  180. /**
  181. * This update has been removed and will not run.
  182. */
  183. function media_library_update_8703() {
  184. // This update function previously added 'edit' and 'delete' buttons to media
  185. // items in the 'media' view. It has been converted to a post-update hook.
  186. // @see media_library_post_update_add_buttons_to_page_view()
  187. }
  188. /**
  189. * Creates the media_library.settings config object.
  190. */
  191. function media_library_update_8704() {
  192. \Drupal::configFactory()
  193. ->getEditable('media_library.settings')
  194. // Enable the advanced UI by default, to preserve existing behavior.
  195. ->set('advanced_ui', TRUE)
  196. ->save();
  197. }