function redirect_update_8102 in Redirect 8
Update settings based on existing settings and Globalredirect settings.
File
- ./
redirect.install, line 85 - Update hooks for the Redirect module.
Code
function redirect_update_8102() {
// Load default configuration.
$redirect_settings = \Drupal::config('redirect.settings');
$globalredirect_settings = \Drupal::config('globalredirect.settings');
$config_factory = \Drupal::configFactory();
$redirect = $config_factory
->getEditable('redirect.settings');
$nonclean_to_clean = $redirect_settings
->get('global_clean');
$admin_path = $redirect_settings
->get('global_admin_paths');
$frontpage_redirect = $redirect_settings
->get('global_home');
$deslash = $redirect_settings
->get('global_deslash');
$message = NULL;
// If Globalredirect configuration exists, use those settings.
if (!$globalredirect_settings
->isNew()) {
$access_check = $globalredirect_settings
->get('access_check');
$normalize_aliases = $globalredirect_settings
->get('normalize_aliases');
$content_location_header = $globalredirect_settings
->get('content_location_header');
$term_path_handler = $globalredirect_settings
->get('term_path_handler');
$deslash = $globalredirect_settings
->get('deslash');
$frontpage_redirect = $globalredirect_settings
->get('frontpage_redirect');
$nonclean_to_clean = $globalredirect_settings
->get('nonclean_to_clean');
$redirect
->set('access_check', $access_check);
$redirect
->set('normalize_aliases', $normalize_aliases);
$redirect
->set('content_location_header', $content_location_header);
$redirect
->set('term_path_handler', $term_path_handler);
$message = 'The Globalredirect module functionality has been merged into redirect, it should be uninstalled now.';
}
else {
$redirect
->set('access_check', FALSE);
$redirect
->set('normalize_aliases', TRUE);
$redirect
->set('content_location_header', FALSE);
$redirect
->set('term_path_handler', TRUE);
}
// Update new redirect settings names.
$redirect
->set('nonclean_to_clean', $nonclean_to_clean);
$redirect
->set('admin_path', $admin_path);
$redirect
->set('frontpage_redirect', $frontpage_redirect);
$redirect
->set('deslash', $deslash);
// Remove old names of redirect settings.
$redirect
->clear('global_clean');
$redirect
->clear('global_admin_paths');
$redirect
->clear('global_home');
$redirect
->clear('global_deslash');
$redirect
->save();
return $message;
}