-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drupal coding standards and disabled frontpage redirecting on sites w…
…hen multi-lingual
- Loading branch information
1 parent
63f9cd1
commit 42cb0fd
Showing
7 changed files
with
293 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,67 @@ | ||
<?php | ||
|
||
namespace Drupal\starter\EventSubscriber; | ||
|
||
use Symfony\Component\Routing\RouteCollection; | ||
use Drupal\Core\Routing\RoutingEvents; | ||
use Drupal\Core\Routing\RouteBuildEvent; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
/** | ||
* | ||
*/ | ||
class RouteSubscriber implements EventSubscriberInterface { | ||
|
||
private $config; | ||
|
||
/* | ||
* get module configuration | ||
/** | ||
* Get module configuration. | ||
*/ | ||
public function getConfig($config) { | ||
$this->config = $config->get('starter.settings'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
* {@inheritdoc} | ||
*/ | ||
public static function getSubscribedEvents() { | ||
$events[RoutingEvents::ALTER] = 'alterRoutes'; | ||
return $events; | ||
} | ||
|
||
/** | ||
* Alters existing routes. | ||
* | ||
* @param \Drupal\Core\Routing\RouteBuildEvent $event | ||
* The route building event. | ||
*/ | ||
* Alters existing routes. | ||
* | ||
* @param \Drupal\Core\Routing\RouteBuildEvent $event | ||
* The route building event. | ||
*/ | ||
public function alterRoutes(RouteBuildEvent $event) { | ||
|
||
// Fetch the collection which can be altered. | ||
$collection = $event->getRouteCollection(); | ||
// The event is fired multiple times so ensure that the user_page route | ||
// is available. | ||
// alter user login url | ||
// alter user login url. | ||
if ($route = $collection->get('user.login')) { | ||
$login = $this->config->get('paths.login'); | ||
// make sure path starts with / | ||
if(strpos($login,'/')!==0) { | ||
$login = '/'.$login; | ||
// Make sure path starts with /. | ||
if (strpos($login, '/') !== 0) { | ||
$login = '/' . $login; | ||
} | ||
$route->setPath($login); | ||
} | ||
// alter user logout url | ||
// Alter user logout url. | ||
if ($route = $collection->get('user.logout')) { | ||
$logout = $this->config->get('paths.logout'); | ||
// make sure path starts with / | ||
if(strpos($logout,'/')!==0) { | ||
$logout = '/'.$logout; | ||
// Make sure path starts with /. | ||
if (strpos($logout, '/') !== 0) { | ||
$logout = '/' . $logout; | ||
} | ||
$route->setPath($logout); | ||
} | ||
// prevent access to default front page view | ||
// Prevent access to default front page view. | ||
if ($route = $collection->get('view.frontpage.page_1')) { | ||
$route->setRequirement('_access', 'false'); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.