unclecheese / silverstripe-gridfield-betterbuttons

Adds new form actions and buttons to the GridField detail form
GNU General Public License v2.0
80 stars 88 forks source link

SilverStripe 4 Actions receiving incorrect gridFieldRequest #191

Open MasonD opened 5 years ago

MasonD commented 5 years ago

In the SilverStripe 4 branch, Actions receive their gridFieldRequest via Injector by asking for

private static $dependencies = [
    'GridFieldRequest' => '%$' . GridFieldDetailForm_ItemRequest::class . '.betterbuttons',
];

However, Injector injects dependencies via the singleton model, and thus caches the result of ItemRequestFactory::create. This means that if you have navigated multiple GridFields deep, every action still receives the GridFieldDetailForm_ItemRequest of the very top GridField.

The actions of every GridField nested underneath another gridfield thus all get the incorrect links, which can be seen by clicking the next or back button, which directs you all the way back to viewing the items of the top level GridField.

There doesn't seem to be any way to tell Injector to inject dependencies without caching as far as I can see. A different approach will probably have to be taken.

I'm not sure if it's the correct solution, but the timing works out such that placing $this->gridFieldRequest = BetterButtons::getGridFieldRequest(); in Action::__construct results in every action receiving the correct ItemRequest.