You are here

function rest_update_8202 in Drupal 8

Re-save all views with a REST display to add new auth defaults.

File

core/modules/rest/rest.install, line 40
Install, update and uninstall functions for the rest module.

Code

function rest_update_8202() {
  $config_factory = \Drupal::configFactory();
  foreach ($config_factory
    ->listAll('views.view.') as $view_config_name) {
    $save = FALSE;
    $view = $config_factory
      ->getEditable($view_config_name);
    $displays = $view
      ->get('display');
    foreach ($displays as $display_name => &$display) {
      if ($display['display_plugin'] == 'rest_export') {
        if (!isset($display['display_options']['auth'])) {
          $display['display_options']['auth'] = [];
          $save = TRUE;
        }
      }
    }
    if ($save) {
      $view
        ->set('display', $displays);
      $view
        ->save(TRUE);
    }
  }
}