Skip to content

Commit

Permalink
register completion listener in service xml and set or unset in compi…
Browse files Browse the repository at this point in the history
…lerpass
  • Loading branch information
alexander-schranz committed Jun 22, 2016
1 parent 08b4195 commit 0df9ecc
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 55 deletions.
3 changes: 3 additions & 0 deletions Controller/CompletionController.php
Expand Up @@ -58,6 +58,9 @@ public function indexAction(Request $request)
// Completion User
$communityManager->completion($user);

// Save User
$this->saveEntities();

// Redirect
$session = $request->getSession();
$redirectTo = $session->get(CompletionListener::SESSION_STORE);
Expand Down
Expand Up @@ -14,19 +14,26 @@
use Sulu\Bundle\CommunityBundle\DependencyInjection\Configuration;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\Reference;

/**
* Register the completion listener when validators are configured.
*/
class CommunityValidatorCompilerPass implements CompilerPassInterface
{
const COMPLETION_LISTENER_SERVICE_ID = 'sulu_community.completion_listener';

/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
// If no listener exists do nothing
if (!$container->hasDefinition(self::COMPLETION_LISTENER_SERVICE_ID)) {
return;
}

// Create Validator References
$config = $container->getParameter('sulu_community.config');

foreach ($config[Configuration::WEBSPACES] as $webspaceKey => $webspaceConfig) {
Expand All @@ -40,13 +47,10 @@ public function process(ContainerBuilder $container)

// Register request listener only when validator exists.
if (!empty($validators)) {
$definition = new DefinitionDecorator('sulu_community.completion_listener.abstract');
$definition = $container->getDefinition(self::COMPLETION_LISTENER_SERVICE_ID);
$definition->replaceArgument(3, $validators);
$definition->addTag('kernel.event_listener', ['event' => 'kernel.request', 'method' => 'onRequest']);
$container->setDefinition(
sprintf('sulu_community.completion_listener', $validators),
$definition
);
} else {
$container->removeDefinition(self::COMPLETION_LISTENER_SERVICE_ID);
}
}
}
2 changes: 0 additions & 2 deletions DependencyInjection/SuluCommunityExtension.php
Expand Up @@ -15,8 +15,6 @@
use Sulu\Bundle\CommunityBundle\Entity\InvalidTypeException;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
Expand Down
36 changes: 0 additions & 36 deletions Resources/config/routing.xml

This file was deleted.

22 changes: 15 additions & 7 deletions Resources/config/routing_website.xml
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>

<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">

<route id="sulu_community.registration" path="/registration">
<default key="_controller">SuluCommunityBundle:Registration:index</default>
Expand All @@ -12,6 +12,10 @@
<default key="_controller">SuluCommunityBundle:Confirmation:index</default>
</route>

<route id="sulu_community.completion" path="/completion">
<default key="_controller">SuluCommunityBundle:Completion:index</default>
</route>

<route id="sulu_community.password_forget" path="/password-forget">
<default key="_controller">SuluCommunityBundle:Password:forget</default>
</route>
Expand All @@ -20,10 +24,6 @@
<default key="_controller">SuluCommunityBundle:Password:reset</default>
</route>

<route id="sulu_community.login" path="/login">
<default key="_controller">SuluCommunityBundle:Login:index</default>
</route>

<route id="sulu_community.user_confirm" path="/_community/confirm">
<default key="_controller">SuluCommunityBundle:BlacklistConfirmation:confirm</default>
</route>
Expand All @@ -32,5 +32,13 @@
<default key="_controller">SuluCommunityBundle:BlacklistConfirmation:deny</default>
</route>

<route id="sulu_community.logout" path="/logout" />
<route id="sulu_community.login" path="/login">
<default key="_controller">SuluCommunityBundle:Login:index</default>
</route>

<route id="sulu_community.login" path="/login">
<default key="_controller">SuluCommunityBundle:Login:index</default>
</route>

<route id="sulu_community.logout" path="/logout"/>
</routes>
8 changes: 5 additions & 3 deletions Resources/config/services.xml
Expand Up @@ -61,13 +61,15 @@
</service>

<!-- Completion Listener -->
<service id="sulu_community.completion_listener.abstract"
class="Sulu\Bundle\CommunityBundle\EventListener\CompletionListener"
abstract="true">
<service id="sulu_community.completion_listener"
class="Sulu\Bundle\CommunityBundle\EventListener\CompletionListener">
<argument type="service" id="sulu_core.webspace.request_analyzer" />
<argument type="service" id="router" />
<argument type="service" id="security.token_storage" />
<argument type="collection" />

<tag name="kernel.event_listener" event="kernel.request" method="onRequest" />
<tag name="sulu.context" context="website" />
</service>

<!-- sulu-admin -->
Expand Down

0 comments on commit 0df9ecc

Please sign in to comment.