Override Admin Controller is creating an issue.

I am using version 6.7.0

I am trying override the UserController in 2 different ways but facing challenges:

Procedure 1.

Creating the UserController and extends it from the AdminController.

namespace Pepsico\COPBundle\Controller\Admin;

use Pimcore\Bundle\AdminBundle\Controller\AdminController;
use Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse;
use Pimcore\Config;
use Pimcore\Controller\EventedControllerInterface;
use Pimcore\Logger;
use Pimcore\Model\DataObject;
use Pimcore\Model\Element;
use Pimcore\Model\User;
use Pimcore\Tool;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBagInterface;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

class UserController extends AdminController
{
/**

  • @route("/admin/user/update-current-user", name=“pimcore_admin_user_updatecurrentuser”, methods={“PUT”})
  • @param Request $request
  • @return JsonResponse
    */
    public function updateCurrentUserAction(Request $request)
    {

    }
    }

In this way I am getting the error that the route pimcore_admin_user_updatecurrentuser does not exists.

Procedure 2

For the same I am providing the zip

PimcoreModBundle.zip

In this way I have to keep all the methods in the UserController then only its working.

Please let me know the exact way to achieve the same.

Hi

if you want to override UserController extend it, not Controller\Admin.
Moreover, do not change the routing - so stay with ‘/user/update-current-user’.

use Pimcore\Bundle\AdminBundle\Controller\Admin\UserController as BaseUserController;

class UserController extends BaseUserController {

/**
* @Route("/user/update-current-user", methods={“PUT”})
*
* @param Request $request
*
* @return JsonResponse
*/
public function updateCurrentUserAction(Request $request)
{

}
}

The main problem is that when I am overriding the Controller all the methods I need to override if I am only overrding the a specific method its not working.

Please, do upload your file to look at it.
With pimcoreModBundle you can override a controller and public methods in a base controller are normally visible.

Can you please override the UserController and only extends the method “updateAction” in PIMCORE version 6.7.0

I recently, after updating, had a problem with my own solution based on the PimcoreModBundle example. In my case I had to remove the controller service definition from my services.yml. I had a catchall definition like below that caused the problem.

my_overrides_bundle:
    resource: "@MyOverridesBundle/Controller/"
    type:     annotation
    prefix:   /admin/myoverrides

Because of that definition the url would change from /admin/object/grid-proxy to /admin/myoverrides/grid-proxy. Then nothing would work because Pimcore was calling the now nonexisting url.

I face the same problem here, this is my file:

<?php

namespace AppBundle\Controller;

use Pimcore\Bundle\AdminBundle\Helper\GridHelperService;
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;
use Pimcore\Bundle\AdminBundle\Controller\Searchadmin\SearchController as BaseSearchController;
use Symfony\Component\Routing\Annotation\Route;


/**
 * @Route("/search")
 */
class SearchController extends BaseSearchController
{
    /**
     * @Route("/find", name="pimcore_admin_searchadmin_search_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, GridHelperService $gridHelperService)
    {
         // removed irrelevant code
    }
}

I get this error in JS console:
Uncaught Error: The route “pimcore_admin_searchadmin_search_quicksearch” does not exist.

What do you have in your services.yml file?

I tried serveral things and am still trying, first was:

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

Next, I tried nothing, same result, reading more symfony docs right now…

Nothing should work. Do you have a routing.yml in your AppBundle?

Just got it to work, I moved the controller to Searchadmin and added this to my routing.yml:

_pimcore_search:
    resource: "@AppBundle/Controller/Searchadmin/"
    type:     annotation
    prefix:   /admin/search
    options:
        expose: true

Grea!. I dont think you need that routing.yml at all since it is exactly the same as the original.