Hello everyone
I would like to know if anybody has tried to decorate a controller ? I made a test with the symfony way to decorate a core controller in a custom module.
The point was to caught the "toggleStatusAction" when you click on the active icon in the customers list (BO) . I followed the prestashop documentation to do so.
So as precised I wrote a service.yml in a config folder:
services:
custom_controller:
class: Test\CustomerDecoration\Controller\NotificationController
decorates: PrestaShopBundle\Controller\Admin\Sell\Customer\CustomerController
arguments: ['@custom_controller.inner']
Here's my class :
<?php
namespace Test\CustomerDecoration\Controller;
use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController;
use PrestaShopBundle\Controller\Admin\Sell\Customer\CustomerController;
/* Here every others use statements but I removed them for clarity */
class NotificationController extends FrameworkBundleAdminController
{
/**
* @var CustomerController
*/
private $decoratedController;
public function __construct(CustomerController $decoratedController)
{
$this->decoratedController = $decoratedController;
}
public function toggleStatusAction($customerId)
{
var_dump($customerId);die;
return $this->decoratedController->toggleStatusAction($customerId);
}
}
I use composer to load my Class and... it worked fine. Somehow. Except this error on the Customer index in the BO :
When I declare this method in my NotificationController it works :
public function indexAction(Request $request, CustomerFilters $filters)
{
return $this->decoratedController->indexAction($request, $filters);
}
But for every other action (edit, view etc) I have to re-declare every methods.
So two differents situations :
1 ) I did something wrong with my code. My bad.
2 ) I did well, which means that everytime we have to decorate a controller, we have to declare again almost every methods ? With "old" override system we just have to extends the Class, and add/modify methods and/or attributes.
Again if I did right, it's going to be a pain to code in my opinion.
So now I'm stuck between those two statements, and I don't know which one is the good one.
If anybody has an answer to that, I'll very interested.