function rest_view_presave in Drupal 8
Implements hook_ENTITY_TYPE_presave().
See also
File
- core/
modules/ rest/ rest.module, line 44 - RESTful web services module.
Code
function rest_view_presave(ViewEntityInterface $view) {
// Fix the auth options on import, much like what rest_update_8401() does.
$auth_providers = \Drupal::service('authentication_collector')
->getSortedProviders();
$process_auth = function ($auth_option) use ($auth_providers) {
foreach ($auth_providers as $provider_id => $provider_data) {
// The provider belongs to the module that declares it as a service.
if (strtok($provider_data->_serviceId, '.') === $auth_option) {
return $provider_id;
}
}
return $auth_option;
};
foreach (array_keys($view
->get('display')) as $display_id) {
$display =& $view
->getDisplay($display_id);
if ($display['display_plugin'] === 'rest_export' && !empty($display['display_options']['auth'])) {
$display['display_options']['auth'] = array_map($process_auth, $display['display_options']['auth']);
}
}
}