How to rewrite SearchController on PimCore 5.6.5

I want to customize the findAction() of Pimcore\Bundle\AdminBundle\Controller\Searchadmin\SearchController, however i found nothing on how to rewrite this Controller, it seems to not be a service so i can’t use the services.yml

I use Pimcore 5.6.5, any idea ?
Thank you :slight_smile:

Well, all controllers are registered as services in the container.

Run php bin/console debug:container Pimcore\Bundle\AdminBundle\Controller\Searchadmin\SearchController in your project directory and you will see the service ID and the class.

So, it appears it is a service, fine !
And i can see my other controller, AppBundle\Controller\Searchadmin\SearchController

So i provided /src/AppBundle/Resources/config/services.yml like this :
services:
# default configuration for services in this file
_defaults:
# automatically injects dependencies in your services
autowire: true
# automatically registers your services as commands, event subscribers, etc.
autoconfigure: true

    # auto-register all controllers as services
    AppBundle\Controller\:
        resource: '../../Controller'
        public: true
        tags: ['controller.service_arguments']

    Pimcore\Bundle\AdminBundle\Controller\Searchadmin\SearchController:
      class: AppBundle\Controller\Searchadmin\SearchController

and now i got an error :
### (1/1) FileLocatorFileNotFoundException

The file "../../src/AppBundle/Listener/Entity" does not exist (in: /var/www/pimcore/src/AppBundle/DependencyInjection/../Resources/config).

Seems like i’m missing a dependency ?

Thank you !

Sorry, i did not precised but, i was trying to get the Listener Entity because i had another error :

Controller “AppBundle\Controller\Searchadmin\SearchController::findAction()” requires that you provide a value for the “$eventDispatcher” argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one.

Maybe there is another way to get rid of this error, my bad.

Well, i’m stuck with this error :

Controller “AppBundle\Controller\Searchadmin\SearchController::findAction()” requires that you provide a value for the “$eventDispatcher” argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one.

Controller code looks like this :

namespace AppBundle\Controller\Searchadmin;

use Pimcore\Bundle\AdminBundle\Controller\Searchadmin\SearchController as SearchadminObjectController;
use Pimcore\Event\AdminEvents;
use Pimcore\Model\Asset;
use Pimcore\Model\DataObject;
use Pimcore\Model\Document;
use Pimcore\Model\Element;
use Pimcore\Model\Search\Backend\Data;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;

class SearchController extends SearchadminObjectController
{

/**
 * @Route("/find", methods={"GET", "POST"})
 *
 * @param Request $request
 * @return JsonResponse
 *
 * @todo: $conditionTypeParts could be undefined
 * @todo: $conditionSubtypeParts could be undefined
 * @todo: $conditionClassnameParts could be undefined
 * @todo: $data could be undefined
 */
public function findAction(Request $request, EventDispatcherInterface $eventDispatcher)
{
}

}

I tried to change my services.yml like this :

services:
# default configuration for services in this file
_defaults:
# automatically injects dependencies in your services
autowire: true
# automatically registers your services as commands, event subscribers, etc.
autoconfigure: true

# auto-register all controllers as services
AppBundle\Controller\:
    resource: '../../Controller'
    public: true
    tags: ['controller.service_arguments']

Pimcore\Bundle\AdminBundle\Controller\Searchadmin\SearchController:
    class: AppBundle\Controller\Searchadmin\SearchController
    tags: ['controller.service_arguments']
    arguments:
        $eventDispatcher: '@event_dispatcher'

But this ain’t working.
By chance do you know what am i missing ?
Thank you !

See here: How to override Admin controller or action

Be aware that you can use in most cases event listeners. But if you still need to override a controller you have to do it via compiler pass etc. like described in linked bundle above. Especially take a look to the DependencyInjection part