/**
* Implements hook_preprocess_HOOK().
*/
function EXAMPLE_preprocess_page(&$variables) {
 $route_name = \Drupal::routeMatch()->getRouteName();
 if ($route_name == 'entity.user.canonical') {
   $current_user = \Drupal::currentUser();
   $roles = $current_user->getRoles();
   if (!in_array('editor', $roles) && $current_user->id() > 1) {
     $url = Url::fromRoute('entity.user.edit_form', ['user' => $current_user->id()]);
     $response = new RedirectResponse($url->toString());
     $response->send();
   }
 }
 $variables['#cache']['contexts'][] = 'session';
}