You are here

function _media_entity_update_views in Media entity 8.2

Updates any views that use the entity:media_bundle argument validator.

1 call to _media_entity_update_views()
media_entity_update_8201 in ./media_entity.install
Replace Media Entity with Media.

File

./media_entity.install, line 538
Install, uninstall and update hooks for Media entity module.

Code

function _media_entity_update_views() {
  $config_factory = \Drupal::configFactory();
  foreach ($config_factory
    ->listAll('views.view') as $name) {
    $view = $config_factory
      ->getEditable($name);
    $changed = FALSE;
    foreach ($view
      ->get('display') as $display_id => $display) {
      $key = "display.{$display_id}.display_options.arguments";

      // If there are no arguments, get() will return NULL, which is [] when
      // cast to an array.
      $arguments = (array) $view
        ->get($key);
      foreach ($arguments as $id => $argument) {
        if (isset($argument['validate']) && $argument['validate']['type'] == 'entity:media_bundle') {
          $view
            ->set("{$key}.{$id}.validate.type", 'entity:media_type');
          $changed = TRUE;
        }
      }
    }
    if ($changed) {
      $view
        ->save();
    }
  }
}