Skip to content

Commit

Permalink
Merge pull request #304 from dadaxr/4.2
Browse files Browse the repository at this point in the history
Merge pull request #277 from Raistlfiren/hotfix-synfomy-events
  • Loading branch information
bobdenotter committed Aug 21, 2020
2 parents 7726a7e + c369c8d commit 667d5e4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
7 changes: 4 additions & 3 deletions docs/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ BoltForms exposes a number of listeners, that proxy Symfony Forms listeners:
- `BoltFormsEvents::PRE_SET_DATA`
- `BoltFormsEvents::POST_SET_DATA`

Each of these match Symfony's constants, just with the BoltForms class name/prefix.
Each of these match Symfony's constants, just with the BoltForms class name/prefix.
**Please note that the class `BoltFormsEvents` wraps around the Symfony `FormEvents`.**

There are also events that trigger during the data processing:

Expand Down Expand Up @@ -185,9 +186,9 @@ class Extension extends SimpleExtension
}


public function myCallback(ProcessorEvent $event)
public function myCallback(BoltFormsEvent $event)
{
if ($event->getFormName() === 'my_form') {
if ($event->getEvent()->getFormName() === 'my_form') {

// Get the data from the event
$data = $event->getData();
Expand Down
2 changes: 1 addition & 1 deletion src/BoltForms.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ private function createFormBuilder($formName, $type = BoltFormType::class, $data
{
return $this->app['form.factory']
->createNamedBuilder($formName, $type, $data, $options)
->addEventSubscriber(new SymfonyFormProxySubscriber())
->addEventSubscriber(new SymfonyFormProxySubscriber($this->app))
->addModelTransformer(new EntityTransformer())
;
}
Expand Down
16 changes: 15 additions & 1 deletion src/Subscriber/SymfonyFormProxySubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Silex\Application;

/**
* Dedicated subscriber interface for BoltForms
Expand All @@ -34,6 +35,19 @@
*/
class SymfonyFormProxySubscriber implements EventSubscriberInterface
{
/** @var Application $app */
protected $app;

/**
* SymfonyFormProxySubscriber constructor.
*
* @param Application $app
*/
public function __construct(Application $app)
{
$this->app = $app;
}

/**
* Events that BoltFormsSubscriber subscribes to
*
Expand Down Expand Up @@ -127,6 +141,6 @@ public function postSubmit(FormEvent $event, $eventName, $dispatcher)
protected function dispatch($eventName, FormEvent $event, $formsEventName, EventDispatcher $dispatcher)
{
$event = new BoltFormsEvent($event, $formsEventName);
$dispatcher->dispatch($eventName, $event);
$this->app['dispatcher']->dispatch($eventName, $event);
}
}

0 comments on commit 667d5e4

Please sign in to comment.