Commit 8087de55 authored by Kunal Singh's avatar Kunal Singh Committed by Nikunj Kotecha
Browse files

Issue #3308765 by kunal_singh:...

Issue #3308765 by kunal_singh: Symfony\Component\Routing\Exception\ResourceNotFoundException: No routes found
parent 24a8b8c6
Loading
Loading
Loading
Loading
+17 −4
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ namespace Drupal\external_hreflang\EventSubscriber;

use Drupal\Core\Path\PathMatcherInterface;
use Drupal\Core\Url;
use Drupal\Core\Logger\LoggerChannelTrait;
use Drupal\external_hreflang\Event\ExternalHreflangGetCurrentUrlEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RequestStack;
@@ -15,6 +16,8 @@ use Symfony\Component\HttpFoundation\RequestStack;
 */
class ExternalHreflangGetCurrentUrlEventSubscriber implements EventSubscriberInterface {

  use LoggerChannelTrait;

  /**
   * The path matcher.
   *
@@ -61,12 +64,22 @@ class ExternalHreflangGetCurrentUrlEventSubscriber implements EventSubscriberInt
   *   Event object.
   */
  public function onGetCurrentUrlEvent(ExternalHreflangGetCurrentUrlEvent $event) {
    try {
      if ($this->pathMatcher->isFrontPage()) {
        $url = Url::fromRoute('<front>');
      }
      else {
        $url = Url::createFromRequest($this->requestStack->getCurrentRequest());
      }
    }
    catch (\Exception $e) {
      $this->getLogger('ExternalHreflangGetCurrentUrlEventSubscriber')->error('Error occurred while getting the url. Message: @message', [
        '@message' => $e->getMessage(),
      ]);

      // Store the empty url.
      $url = Url::fromRoute('<none>');
    }

    $event->setCurrentUrl($url);
  }