Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return route after sending mail ? #5

Closed
thomthom33 opened this issue Jul 30, 2018 · 12 comments
Closed

return route after sending mail ? #5

thomthom33 opened this issue Jul 30, 2018 · 12 comments
Assignees

Comments

@thomthom33
Copy link

hi, once overrided email layout, works fine, thank you ! but form still displayed....
This is a question : is there a way to invoke a route after email sending ?
Alain

@LaurentMarquet
Copy link
Member

LaurentMarquet commented Jul 30, 2018

The session variable redirectUrl is the one used to redirect, so we can define it, but it was not "easy" to modify this variable, as it is defined via $contactFormService->defineReferer();.
To be able to do so, I have added the Request to the event (v1.9.4), so now you can catch ContactFormEvent::SEND_FORM with the following code:

namespace AppBundle\Listener;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use c975L\ContactFormBundle\Event\ContactFormEvent;

class ContactFormListener implements EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        return array(
            ContactFormEvent::SEND_FORM => 'sendForm',
        );
    }

    public function sendForm($event)
    {
        //Updates url to redirect
        $event->getRequest()->getSession()->set('redirectUrl', 'https://example.com');
    }
}

@LaurentMarquet
Copy link
Member

As I think it's more logical, I've moved the defineReferer() call at the top of ContactFormController->display() So you can now catch the event ContactFormEvent::CREATE_FORM (in place of SEND_FORM), that's the case documented in the README.md.

@thomthom33
Copy link
Author

hi,
i've declared the listener according your documentation, but symfony profiler says
capture du 2018-07-31 14-59-30
it is not called.... contact form is not replaced by precedent view... i must precise /contact is called from knpmenubundle, and i've updated to your last release of contactform (sf 3.413)
Alain

@LaurentMarquet
Copy link
Member

Yes you're right! The event is not dispatched...
I've found the reason. It's because before I was using $dispatcher = $this->get('event_dispatcher') but I've moved to $dispatcher = new EventDispatcher();' to avoid use of $this->get()` but it doesn't dispatch anymore...
I have to fix it, unless you want to make a PR.

I have also mixed in my mind Listener and Subscriber, I will also correct it in the README.md.
Thanks

@thomthom33
Copy link
Author

i'm totally noob on PR, i'm waiting for you to fix it :-)

@LaurentMarquet
Copy link
Member

I was (and always am) a noob for PRs and other matters. I learn by making ;-)
You can find useful information for PRs.
PR #7 is the first that I submit containing 2 commits, I didn't know how to do before. You can have a look at it, as it's not a big one, then you can learn if you want.

Concerning the solution, in fact I had to inject EventDispatcherInterface. That's solved with v1.9.5.1

@thomthom33
Copy link
Author

thomthom33 commented Aug 1, 2018

capture du 2018-08-01 20-14-11
sorry but a i have an error when updating via composer, see screenshot,
capture du 2018-08-01 20-08-40

@thomthom33
Copy link
Author

and thanks for the advices about PR.
i found this that seems very complete : https://blog.zenika.com/2017/01/24/pull-request-demystifie/

@LaurentMarquet
Copy link
Member

Doing too many things at the same time...
It was a missing folder in 975L/EmailBundle, now solved with 975L/EmailBundle#2
Thanks

@thomthom33
Copy link
Author

tested Ok, thanks !

@LaurentMarquet
Copy link
Member

Thanks for the link on PRs that answered me a question on how to treat the PRs on the maintainer’s side :-)

@AlainT
Copy link

AlainT commented Aug 1, 2018

you're welcome !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants