vendor/sonata-project/admin-bundle/src/Controller/HelperController.php line 34

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of the Sonata Project package.
  5.  *
  6.  * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace Sonata\AdminBundle\Controller;
  12. use Sonata\AdminBundle\Action\AppendFormFieldElementAction;
  13. use Sonata\AdminBundle\Action\GetShortObjectDescriptionAction;
  14. use Sonata\AdminBundle\Action\RetrieveAutocompleteItemsAction;
  15. use Sonata\AdminBundle\Action\RetrieveFormFieldElementAction;
  16. use Sonata\AdminBundle\Action\SetObjectFieldValueAction;
  17. use Sonata\AdminBundle\Admin\AdminHelper;
  18. use Sonata\AdminBundle\Admin\Pool;
  19. use Symfony\Component\HttpFoundation\JsonResponse;
  20. use Symfony\Component\HttpFoundation\Request;
  21. use Symfony\Component\HttpFoundation\Response;
  22. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  23. use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  24. use Symfony\Component\Validator\Validator\ValidatorInterface;
  25. use Twig\Environment;
  26. @trigger_error(
  27.     'The '.__NAMESPACE__.'\HelperController class is deprecated since version 3.38.0 and will be removed in 4.0.'
  28.     .' Use actions inside Sonata\AdminBundle\Action instead.',
  29.     E_USER_DEPRECATED
  30. );
  31. /**
  32.  * NEXT_MAJOR: remove this class.
  33.  *
  34.  * @deprecated since version 3.38.0, to be removed in 4.0. Use actions inside Sonata\AdminBundle\Action instead.
  35.  *
  36.  * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  37.  */
  38. class HelperController
  39. {
  40.     /**
  41.      * @var Environment
  42.      */
  43.     protected $twig;
  44.     /**
  45.      * @var AdminHelper
  46.      */
  47.     protected $helper;
  48.     /**
  49.      * @var Pool
  50.      */
  51.     protected $pool;
  52.     /**
  53.      * @var ValidatorInterface
  54.      */
  55.     protected $validator;
  56.     /**
  57.      * @param ValidatorInterface $validator
  58.      */
  59.     public function __construct(Environment $twigPool $poolAdminHelper $helper$validator)
  60.     {
  61.         // NEXT_MAJOR: Move ValidatorInterface check to method signature
  62.         if (!($validator instanceof ValidatorInterface)) {
  63.             throw new \InvalidArgumentException(
  64.                 'Argument 4 is an instance of '.\get_class($validator).', expecting an instance of'
  65.                 .' \Symfony\Component\Validator\Validator\ValidatorInterface'
  66.             );
  67.         }
  68.         $this->twig $twig;
  69.         $this->pool $pool;
  70.         $this->helper $helper;
  71.         $this->validator $validator;
  72.     }
  73.     /**
  74.      * @throws NotFoundHttpException
  75.      *
  76.      * @return Response
  77.      */
  78.     public function appendFormFieldElementAction(Request $request)
  79.     {
  80.         $action = new AppendFormFieldElementAction($this->twig$this->pool$this->helper);
  81.         return $action($request);
  82.     }
  83.     /**
  84.      * @throws NotFoundHttpException
  85.      *
  86.      * @return Response
  87.      */
  88.     public function retrieveFormFieldElementAction(Request $request)
  89.     {
  90.         $action = new RetrieveFormFieldElementAction($this->twig$this->pool$this->helper);
  91.         return $action($request);
  92.     }
  93.     /**
  94.      * @throws NotFoundHttpException|\RuntimeException
  95.      *
  96.      * @return Response
  97.      */
  98.     public function getShortObjectDescriptionAction(Request $request)
  99.     {
  100.         $action = new GetShortObjectDescriptionAction($this->twig$this->pool);
  101.         return $action($request);
  102.     }
  103.     /**
  104.      * @return Response
  105.      */
  106.     public function setObjectFieldValueAction(Request $request)
  107.     {
  108.         $action = new SetObjectFieldValueAction($this->twig$this->pool$this->validator);
  109.         return $action($request);
  110.     }
  111.     /**
  112.      * Retrieve list of items for autocomplete form field.
  113.      *
  114.      * @throws \RuntimeException
  115.      * @throws AccessDeniedException
  116.      *
  117.      * @return JsonResponse
  118.      */
  119.     public function retrieveAutocompleteItemsAction(Request $request)
  120.     {
  121.         $action = new RetrieveAutocompleteItemsAction($this->pool);
  122.         return $action($request);
  123.     }
  124. }