Skip to content

Commit

Permalink
Issue #83: Make /user/register route aware of the new config.
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiu-cristea committed Jun 4, 2019
1 parent 0aa3928 commit 9f0c39d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
3 changes: 2 additions & 1 deletion oe_authentication.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ services:
tags:
- { name: access_check, applies_to: _external_user_access_check }
oe_authentication.route_subscriber:
class: \Drupal\oe_authentication\Routing\RouteSubscriber
class: Drupal\oe_authentication\Routing\RouteSubscriber
arguments: ['@config.factory']
tags:
- { name: event_subscriber }
oe_authentication.event_subscriber:
Expand Down
33 changes: 27 additions & 6 deletions src/Routing/RouteSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Drupal\oe_authentication\Routing;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
Expand All @@ -13,6 +14,23 @@
*/
class RouteSubscriber extends RouteSubscriberBase {

/**
* The config factory service.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;

/**
* Constructs a new route event subscriber.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory service.
*/
public function __construct(ConfigFactoryInterface $config_factory) {
$this->configFactory = $config_factory;
}

/**
* {@inheritdoc}
*/
Expand All @@ -33,12 +51,15 @@ protected function alterRoutes(RouteCollection $collection): void {
}

// Replace the core register route controller.
$route = $collection->get('user.register');
if ($route instanceof Route) {
$defaults = $route->getDefaults();
unset($defaults['_form']);
$defaults['_controller'] = '\Drupal\oe_authentication\Controller\RegisterController::register';
$route->setDefaults($defaults);
$config = $this->configFactory->get('oe_authentication.settings');
if ($config->get('redirect_user_register_route')) {
$route = $collection->get('user.register');
if ($route instanceof Route) {
$defaults = $route->getDefaults();
unset($defaults['_form']);
$defaults['_controller'] = '\Drupal\oe_authentication\Controller\RegisterController::register';
$route->setDefaults($defaults);
}
}

// Replace the cas callback route controller.
Expand Down

0 comments on commit 9f0c39d

Please sign in to comment.