You need to replace the calls to `drupal_goto()`. 

Write this line at top of the file.

    use \Symfony\Component\HttpFoundation\RedirectResponse;

Replace the call to `drupal_goto()` with the following code.

    $response = new RedirectResponse($url); // $url = '<front>';
    $response->send();