-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #83: Listen to ConfgEvents::SAVE to detect changes instead of f…
…orm API.
- Loading branch information
1 parent
ec18135
commit 8e49cd8
Showing
3 changed files
with
62 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Drupal\oe_authentication\Event; | ||
|
||
use Drupal\Core\Config\ConfigCrudEvent; | ||
use Drupal\Core\Config\ConfigEvents; | ||
use Drupal\Core\Routing\RouteBuilderInterface; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
/** | ||
* Acts when oe_authentication.settings:redirect_user_register_route changes. | ||
*/ | ||
class UserRegisterRouteRedirectConfigSubscriber implements EventSubscriberInterface { | ||
|
||
/** | ||
* The route builder service. | ||
* | ||
* @var \Drupal\Core\Routing\RouteBuilderInterface | ||
*/ | ||
protected $routeBuilder; | ||
|
||
/** | ||
* Constructs a new event subscriber instance. | ||
* | ||
* @param \Drupal\Core\Routing\RouteBuilderInterface $route_builder | ||
* The route builder service. | ||
*/ | ||
public function __construct(RouteBuilderInterface $route_builder) { | ||
$this->routeBuilder = $route_builder; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function getSubscribedEvents(): array { | ||
return [ | ||
ConfigEvents::SAVE => 'onConfigSave', | ||
]; | ||
} | ||
|
||
/** | ||
* Acts when oe_authentication.settings:redirect_user_register_route changes. | ||
* | ||
* @param \Drupal\Core\Config\ConfigCrudEvent $event | ||
* The config CRUD event. | ||
*/ | ||
public function onConfigSave(ConfigCrudEvent $event): void { | ||
if ($event->getConfig()->getName() === 'oe_authentication.settings') { | ||
if ($event->isChanged('redirect_user_register_route')) { | ||
$this->routeBuilder->rebuild(); | ||
} | ||
} | ||
} | ||
|
||
} |
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