function search_api_update_8104 in Search API 8
Update Views to use the time-based cache plugin for Search API.
File
- ./
search_api.install, line 252 - Install, update and uninstall functions for the Search API module.
Code
function search_api_update_8104() {
$config_factory = \Drupal::configFactory();
$changed = [];
foreach ($config_factory
->listAll('views.view.') as $view_config_name) {
$view = $config_factory
->getEditable($view_config_name);
$displays = $view
->get('display');
$updated = FALSE;
foreach ($displays as $id => $display) {
if (($display['display_options']['cache']['type'] ?? '') === 'search_api') {
$displays[$id]['display_options']['cache']['type'] = 'search_api_time';
$updated = TRUE;
}
}
if ($updated) {
$view
->set('display', $displays);
// Mark the resulting configuration as trusted data. This avoids issues
// with future schema changes.
$view
->save(TRUE);
$changed[] = $view
->get('id');
}
}
if (!empty($changed)) {
return \Drupal::translation()
->translate('The following views have been updated to use the time-based cache plugin: @ids', [
'@ids' => implode(', ', array_unique($changed)),
]);
}
return NULL;
}