Commit 0956bab5 authored by Tino Goratsch's avatar Tino Goratsch

When the homepage is being displayed, set the canonical URL to the website root

parent db48785a
......@@ -8,6 +8,7 @@ namespace ACP3\Modules\ACP3\Seo\Event\Listener;
use ACP3\Core\Application\Event\ControllerActionBeforeDispatchEvent;
use ACP3\Core\Controller\AreaEnum;
use ACP3\Core\Environment\ApplicationPath;
use ACP3\Core\Http\RequestInterface;
use ACP3\Core\Router\RouterInterface;
use ACP3\Modules\ACP3\Seo\Core\Router\Aliases;
......@@ -35,16 +36,22 @@ class OnControllerActionBeforeDispatchListener
* @var \ACP3\Modules\ACP3\Seo\Helper\MetaStatements
*/
protected $metaStatements;
/**
* @var ApplicationPath
*/
private $applicationPath;
/**
* OnFrontControllerBeforeDispatchListener constructor.
*
* @param ApplicationPath $applicationPath
* @param \ACP3\Core\Http\RequestInterface $request
* @param \ACP3\Core\Router\RouterInterface $router
* @param \ACP3\Modules\ACP3\Seo\Core\Router\Aliases $aliases
* @param \ACP3\Modules\ACP3\Seo\Helper\MetaStatements $metaStatements
*/
public function __construct(
ApplicationPath $applicationPath,
RequestInterface $request,
RouterInterface $router,
Aliases $aliases,
......@@ -54,6 +61,16 @@ class OnControllerActionBeforeDispatchListener
$this->router = $router;
$this->aliases = $aliases;
$this->metaStatements = $metaStatements;
$this->applicationPath = $applicationPath;
}
/**
* @param \ACP3\Core\Application\Event\ControllerActionBeforeDispatchEvent $event
*/
public function onBeforeDispatch(ControllerActionBeforeDispatchEvent $event)
{
$this->setCanonicalForExistingUriAlias($event);
$this->setCanonicalForHomepage();
}
/**
......@@ -61,7 +78,7 @@ class OnControllerActionBeforeDispatchListener
*
* @param \ACP3\Core\Application\Event\ControllerActionBeforeDispatchEvent $event
*/
public function onBeforeDispatch(ControllerActionBeforeDispatchEvent $event)
private function setCanonicalForExistingUriAlias(ControllerActionBeforeDispatchEvent $event)
{
if ($this->isInFrontend($event) && $this->uriAliasExists()) {
$this->metaStatements->setCanonicalUri($this->router->route($this->request->getQuery()));
......@@ -87,4 +104,14 @@ class OnControllerActionBeforeDispatchListener
return $this->aliases->uriAliasExists($this->request->getQuery()) === true
&& $this->request->getPathInfo() !== $this->aliases->getUriAlias($this->request->getQuery()) . '/';
}
/**
* If we are currently displaying the homepage, set the canonical URL to the website root
*/
private function setCanonicalForHomepage()
{
if ($this->request->isHomepage()) {
$this->metaStatements->setCanonicalUri($this->applicationPath->getWebRoot());
}
}
}
......@@ -56,6 +56,10 @@ class MetaStatements
* @var string
*/
private $metaRobots = '';
/**
* @var bool
*/
private $isActive;
/**
* MetaStatements constructor.
......@@ -91,7 +95,7 @@ class MetaStatements
/**
* Returns the meta tags of the current page
*
* @return string
* @return array
*/
public function getMetaTags()
{
......
......@@ -2,6 +2,7 @@ services:
seo.event.on_controller_action_before_dispatch_listener:
class: ACP3\Modules\ACP3\Seo\Event\Listener\OnControllerActionBeforeDispatchListener
arguments:
- '@core.environment.application_path'
- '@core.http.request'
- '@core.router'
- '@seo.core.router.aliases'
......
......@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed
- Added an explicit breadcrumb to the imprint controller action of the contact module, as the imprint is not directly associated with the contact form
- The titles of the programmatically breadcrumb steps now always take precedence over the ones from the database
- When the homepage is being displayed, set the canonical URL to the website root
## [4.13.1] - 2017-10-21
### Fixed
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment