media.post_update.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * @file
  4. * Post update functions for Media.
  5. */
  6. use Drupal\user\RoleInterface;
  7. use Drupal\views\Views;
  8. /**
  9. * Clear caches due to changes in local tasks and action links.
  10. */
  11. function media_post_update_collection_route() {
  12. // Empty post-update hook.
  13. }
  14. /**
  15. * Clear caches due to the addition of a Media-specific entity storage handler.
  16. */
  17. function media_post_update_storage_handler() {
  18. // Empty post-update hook.
  19. }
  20. /**
  21. * Keep media items viewable at /media/{id}.
  22. */
  23. function media_post_update_enable_standalone_url() {
  24. $config = \Drupal::configFactory()->getEditable('media.settings');
  25. if ($config->get('standalone_url') === NULL) {
  26. $config->set('standalone_url', TRUE)->save(TRUE);
  27. }
  28. }
  29. /**
  30. * Add a status extra filter to the media view default display.
  31. */
  32. function media_post_update_add_status_extra_filter() {
  33. $view = Views::getView('media');
  34. if (!$view) {
  35. return;
  36. }
  37. // Fetch the filters from the default display and add the new 'status_extra'
  38. // filter if it does not yet exist.
  39. $default_display = $view->getDisplay();
  40. $filters = $default_display->getOption('filters');
  41. if (!isset($filters['status_extra'])) {
  42. $filters['status_extra'] = [
  43. 'group_info' => [
  44. 'widget' => 'select',
  45. 'group_items' => [],
  46. 'multiple' => FALSE,
  47. 'description' => '',
  48. 'default_group_multiple' => [],
  49. 'default_group' => 'All',
  50. 'label' => '',
  51. 'identifier' => '',
  52. 'optional' => TRUE,
  53. 'remember' => FALSE,
  54. ],
  55. 'group' => 1,
  56. 'relationship' => 'none',
  57. 'exposed' => FALSE,
  58. 'expose' => [
  59. 'use_operator' => FALSE,
  60. 'remember' => FALSE,
  61. 'operator_id' => '',
  62. 'multiple' => FALSE,
  63. 'description' => '',
  64. 'required' => FALSE,
  65. 'label' => '',
  66. 'operator_limit_selection' => FALSE,
  67. 'operator' => '',
  68. 'identifier' => '',
  69. 'operator_list' => [],
  70. 'remember_roles' => [RoleInterface::AUTHENTICATED_ID => RoleInterface::AUTHENTICATED_ID],
  71. ],
  72. 'entity_type' => 'media',
  73. 'value' => '',
  74. 'field' => 'status_extra',
  75. 'is_grouped' => FALSE,
  76. 'admin_label' => '',
  77. 'operator' => '=',
  78. 'table' => 'media_field_data',
  79. 'plugin_id' => 'media_status',
  80. 'id' => 'status_extra',
  81. 'group_type' => 'group',
  82. ];
  83. $default_display->setOption('filters', $filters);
  84. $view->save();
  85. return t("The 'Published status or admin user' filter was added to the %label view.", [
  86. '%label' => $view->storage->label(),
  87. ]);
  88. }
  89. }