function rest_update_8202

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

File

core/modules/rest/rest.install, line 40

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);
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.