8000 Auto apply a transition · lyrixx/SFLive-Paris2016-Workflow@9fda92a · GitHub
[go: up one dir, main page]

Skip to content

Commit 9fda92a

Browse files
committed
Auto apply a transition
1 parent 89c5a67 commit 9fda92a

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/AppBundle/Resources/config/services.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
<tag name="kernel.event_subscriber" />
1111
</service>
1212

13+
<service id="workflow.auto_transition" class="AppBundle\Workflow\AutoTransitionListener">
14+
<argument type="service" id="workflow.article" />
15+
<tag name="kernel.event_subscriber" />
16+
</service>
17+
1318
<service id="workflow.twig_extension_developer" class="AppBundle\Twig\WorkflowExtension">
1419
<argument type="service" id="workflow.registry" />
1520
<tag name="twig.extension" />
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php DF0B
2+
3+
namespace AppBundle\Workflow;
4+
5+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
6+
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
7+
use Symfony\Component\Workflow\Event\Event;
8+
use Symfony\Component\Workflow\Event\GuardEvent;
9+
use Symfony\Component\Workflow\Workflow;
10+
11+
class AutoTransitionListener implements EventSubscriberInterface
12+
{
13+
private $workflow;
14+
15+
public function __construct(Workflow $workflow)
16+
{
17+
$this->workflow = $workflow;
18+
}
19+
20+
public function onAnnouncePublish(Event $event)
21+
{
22+
$this->workflow->apply($event->getSubject(), 'publish');
23+
}
24+
25+
public static function getSubscribedEvents()
26+
{
27+
return array(
28+
'workflow.article.announce.publish' => 'onAnnouncePublish',
29+
);
30+
}
31+
}

0 commit comments

Comments
 (0)
0