You are here

function lightning_media_update_8012 in Lightning Media 8.3

Same name and namespace in other branches
  1. 8.4 lightning_media.install \lightning_media_update_8012()
  2. 8 lightning_media.install \lightning_media_update_8012()
  3. 8.2 lightning_media.install \lightning_media_update_8012()

Adds the library filter to the media view's Entity Browser display.

File

./lightning_media.install, line 231
Contains install and update routines for Lightning Media.

Code

function lightning_media_update_8012() {

  /** @var \Drupal\entity_browser\EntityBrowserInterface $browser */
  $browser = EntityBrowser::load('media_browser');
  if (empty($browser)) {
    return;
  }

  /** @var \Drupal\entity_browser\WidgetInterface $widget */
  foreach ($browser
    ->getWidgets() as $widget) {
    if ($widget
      ->getPluginId() == 'view') {
      $configuration = $widget
        ->getConfiguration();
      if ($configuration['settings']['view'] == 'media') {

        /** @var \Drupal\views\ViewEntityInterface $view */
        $view = View::load('media');

        // Reference the display options directly, for readability.
        $display =& $view
          ->getDisplay($configuration['settings']['view_display'])['display_options'];

        // It's possible that the site owner took matters into their own hands
        // and configured the filter already, so only add it if it's not there.
        if (empty($display['filters']['field_media_in_library_value'])) {
          $display['filters']['field_media_in_library_value'] = unserialize('a:14:{s:2:"id";s:28:"field_media_in_library_value";s:5:"table";s:29:"media__field_media_in_library";s:5:"field";s:28:"field_media_in_library_value";s:12:"relationship";s:4:"none";s:10:"group_type";s:5:"group";s:11:"admin_label";s:0:"";s:8:"operator";s:1:"=";s:5:"value";b:1;s:5:"group";i:1;s:7:"exposed";b:0;s:6:"expose";a:10:{s:11:"operator_id";s:0:"";s:5:"label";s:0:"";s:11:"description";s:0:"";s:12:"use_operator";b:0;s:8:"operator";s:0:"";s:10:"identifier";s:0:"";s:8:"required";b:0;s:8:"remember";b:0;s:8:"multiple";b:0;s:14:"remember_roles";a:1:{s:13:"authenticated";s:13:"authenticated";}}s:10:"is_grouped";b:0;s:10:"group_info";a:10:{s:5:"label";s:0:"";s:11:"description";s:0:"";s:10:"identifier";s:0:"";s:8:"optional";b:1;s:6:"widget";s:6:"select";s:8:"multiple";b:0;s:8:"remember";b:0;s:13:"default_group";s:3:"All";s:22:"default_group_multiple";a:0:{}s:11:"group_items";a:0:{}}s:9:"plugin_id";s:7:"boolean";}');
          $view
            ->save();
        }
      }
    }
  }
}