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

Can't redirect with setResponse() in index and show event in ResourceController #10286

Closed
aakashtushar opened this issue Apr 4, 2019 · 2 comments
Labels
Stale Issues and PRs with no recent activity, about to be closed soon.

Comments

@aakashtushar
Copy link

aakashtushar commented Apr 4, 2019

Sylius version affected: 1.2.16

Description
When trying to set RedirectResponse in setResponse(), the ResourceController does not handle the event in indexAction() and showAction().

Steps to reproduce

Listener

class SomeIndexListener {
    public function indexListenerMethod(ResourceControllerEvent $event) {
        ... 
        $event->setResponse(new RedirectResponse($url));
    }
}

event_listener_service.yml

app.listener.product.index:
    class: AppBundle\EventListener\SomeIndexListener
    tags:
      - { name: kernel.event_listener, event: sylius.product.index, method: indexListenerMethod }

Possible Solution

ResourceController

public function indexAction(Request $request) {
    ...
    $event = $this->eventDispatcher->dispatchMultiple(ResourceActions::INDEX, $configuration, $resources);
    if($event->hasResponse()) {
        return $event->getResponse();
    }
    ...
}
@stale
Copy link

stale bot commented Jul 10, 2019

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in a week if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale Issues and PRs with no recent activity, about to be closed soon. label Jul 10, 2019
@Zales0123
Copy link
Member

Hello @aakashtushar, sorry for no response :( SyliusResourceBundle has been extracted to a separate repository some time ago, please, open your issue there https://github.com/Sylius/SyliusResourceBundle/ :) Thank you! 🚀

Zales0123 added a commit to Sylius/SyliusResourceBundle that referenced this issue Jan 7, 2022
…e to redirect (maximehuran, Zales0123)

This PR was merged into the 1.9-dev branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Bug fix?        | no
| New feature?    | yes
| BC breaks?      | no
| Deprecations?   | o
| Related tickets | mentioned in Sylius/Sylius#10286
| License         | MIT


Commits
-------

e973231 Manage event response in show and index action to be able to redirect
812e698 Add PHPSpec tests for event response in show and index
c6baf48 Check call on view handler rather than on protected function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Stale Issues and PRs with no recent activity, about to be closed soon.
Projects
None yet
Development

No branches or pull requests

3 participants