Implementing an age check using InboundPathProcessorInterface I'm trying to create an age checker for a Drupal 8 site. 

I've created a custom module which has a form where the user enters their DOB and my form submit saves a cookie so I know they have passed the age check. Code is as follows:

public function submitForm(array &amp;$form, FormStateInterface $form_state) {
  $day = $form_state-&gt;getValue('day');
  $month = $form_state-&gt;getValue('month');
  $year = $form_state-&gt;getValue('year');

  $timezone = new \DateTimeZone('Africa/Johannesburg');
  $age =
    \DateTime::createFromFormat('d/m/Y', $day . '/' . $month . '/' . $year,
      $timezone)-&gt;diff(new \DateTime('now', $timezone))-&gt;y;

  if ($age &lt; '18') {
    // if less than 18 display the age_check.fail route
    $url = Url::fromRoute('age_check.fail');
    $form_state-&gt;setRedirectUrl($url);
  } else {
    // set cookie so we know this user has passed the age check
    setcookie('age_checked', 1, time()+3600, '/');

    $original_path = $_COOKIE['age_checked_prev_path'];

    if (!empty($original_path) &amp;&amp; $original_path != '/') {
      $redirect_url = Url::fromUserInput($original_path);
      // Add a redirect to requested page. Using $form_state built in redirects.
      $form_state-&gt;setRedirectUrl($redirect_url);
    } else {
      // For everything else, redirect to homepage.
      $form_state-&gt;setRedirect('&lt;front&gt;');
    }
  }

}


Cool that is working fine i get redirected to a age-check-fail page if under 18. If over 18 I should be redirected back to the page I originally wanted to go to. Now I've tried to implement this using a Path Processor. 

   /**
   * Path processor for age_check.
   */
class AgeCheckPathProcessor implements InboundPathProcessorInterface {

/**
 * {@inheritdoc}
 *
 */
public function processInbound($path, Request $request) {
  $alias_manager = \Drupal::service('path.alias_manager');
  $request_alias = $alias_manager-&gt;getAliasByPath($request-&gt;getRequestUri());
  // set cookie with original request path
  setcookie('age_checked_prev_path',$request_alias, time()+3600, '/');

  //get all cookies
  $cookies = $request-&gt;cookies-&gt;all();

  if(!array_key_exists('age_checked', $cookies) &amp;&amp; empty($cookies['age_checked'])){

      // paths to skip age check
      $skip_path = [
        0 =&gt; '/admin',
        1 =&gt; '/user',
        2 =&gt; '/user/login',
        3 =&gt; '/age-check',
        4 =&gt; '/age-check/fail'
      ];

      // loop through each skip path and if match to current request return it
      foreach ($skip_path as $key =&gt; $path) {
        $url = trim($path);
        $url_alias = $alias_manager-&gt;getAliasByPath($url);

        if ($url == $request_alias || $url_alias == $request_alias) {
          // Leave $path intact.
          return $request_alias;
        }
      }

    // show the age check page.
    return '/age-check';
  }
  return $request_alias;
}


This isn't working as intended. One main problem is that coming from the home page, submitting the age check form correctly it still redirects me back to the age check form, if i then enter the url to an article I am allowed access to the site as intended, but trying to go back to the home page still shows the age checker form.

Am I using the Inbound Path Processor class correctly?
service:

  blah.preserved_system_paths_redirect:
    class: Drupal\blah\Redirect\PreservedSystemPathsRedirect
    tags:
      - { name: event_subscriber }


--

&lt;?php

/**
 * @file
 * Contains \Drupal\blah\Redirect\PreservedSystemPathsRedirect.
 */

namespace Drupal\blah\Redirect;

use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Drupal\Core\Routing\RouteMatch;

/**
 * Class PreservedSystemPathsRedirect.
 */
class PreservedSystemPathsRedirect implements EventSubscriberInterface {

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[KernelEvents::REQUEST] = 'checkSystemPaths';
    return $events;
  }

  /**
   * Redirect from original system paths to their new locations.
   *
   * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $response
   *   The created response object that will be returned.
   * @param string $event
   *   The string representation of the event.
   * @param \Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher $event_dispatcher
   *   Event dispatcher that lazily loads listeners and subscribers from the dependency injection
   *   container.
   */
  public function checkSystemPaths(GetResponseEvent $response, $event, ContainerAwareEventDispatcher $event_dispatcher) {
    $routeMatch = RouteMatch::createFromRequest($response-&gt;getRequest());
    $route_name = $routeMatch-&gt;getRouteName();

    switch ($route_name) {
      // Regional settings are now available in the blah/site settings form.
      case 'system.regional_settings':
      // Maintenance mode is now available in the blah/site setting form.
      case 'system.site_maintenance_mode':
        $url = \Drupal::url('blah.settings');
        break;
    }

    if (isset($url)) {
      $returnResponse = new RedirectResponse($url, Response::HTTP_MOVED_PERMANENTLY);
      $response-&gt;setResponse($returnResponse);
    }
  }

}