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

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 Sonata\AdminBundle\Form\DataTransformerResolver;
  20. use Sonata\AdminBundle\Form\DataTransformerResolverInterface;
  21. use Symfony\Component\HttpFoundation\JsonResponse;
  22. use Symfony\Component\HttpFoundation\Request;
  23. use Symfony\Component\HttpFoundation\Response;
  24. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  25. use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  26. use Symfony\Component\Validator\Validator\ValidatorInterface;
  27. use Twig\Environment;
  28. @trigger_error(sprintf(
  29.     'The %s\HelperController class is deprecated since version 3.38.0 and will be removed in 4.0.'
  30.     .' Use actions inside Sonata\AdminBundle\Action instead.',
  31.     __NAMESPACE__
  32. ), \E_USER_DEPRECATED);
  33. /**
  34.  * NEXT_MAJOR: remove this class.
  35.  *
  36.  * @deprecated since sonata-project/admin-bundle 3.38.0, to be removed in 4.0. Use actions inside Sonata\AdminBundle\Action instead.
  37.  *
  38.  * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  39.  */
  40. class HelperController
  41. {
  42.     /**
  43.      * @var Environment
  44.      */
  45.     protected $twig;
  46.     /**
  47.      * @var AdminHelper
  48.      */
  49.     protected $helper;
  50.     /**
  51.      * @var Pool
  52.      */
  53.     protected $pool;
  54.     /**
  55.      * @var ValidatorInterface
  56.      */
  57.     protected $validator;
  58.     /**
  59.      * @var DataTransformerResolver
  60.      */
  61.     private $resolver;
  62.     /**
  63.      * @param ValidatorInterface           $validator
  64.      * @param DataTransformerResolver|null $resolver
  65.      */
  66.     public function __construct(Environment $twigPool $poolAdminHelper $helper$validator$resolver null)
  67.     {
  68.         // NEXT_MAJOR: Move ValidatorInterface check to method signature
  69.         if (!($validator instanceof ValidatorInterface)) {
  70.             throw new \InvalidArgumentException(sprintf(
  71.                 'Argument 4 is an instance of %s, expecting an instance of %s',
  72.                 \get_class($validator),
  73.                 ValidatorInterface::class
  74.             ));
  75.         }
  76.         // NEXT_MAJOR: Move DataTransformerResolver check to method signature
  77.         if (!$resolver instanceof DataTransformerResolverInterface) {
  78.             @trigger_error(sprintf(
  79.                 'Passing other type than %s in argument 4 to %s() is deprecated since sonata-project/admin-bundle 3.76 and will throw %s exception in 4.0.',
  80.                 DataTransformerResolverInterface::class,
  81.                 __METHOD__,
  82.                 \TypeError::class
  83.             ), \E_USER_DEPRECATED);
  84.             $resolver = new DataTransformerResolver();
  85.         }
  86.         $this->twig $twig;
  87.         $this->pool $pool;
  88.         $this->helper $helper;
  89.         $this->validator $validator;
  90.         $this->resolver $resolver;
  91.     }
  92.     /**
  93.      * @throws NotFoundHttpException
  94.      *
  95.      * @return Response
  96.      */
  97.     public function appendFormFieldElementAction(Request $request)
  98.     {
  99.         $action = new AppendFormFieldElementAction($this->twig$this->pool$this->helper);
  100.         return $action($request);
  101.     }
  102.     /**
  103.      * @throws NotFoundHttpException
  104.      *
  105.      * @return Response
  106.      */
  107.     public function retrieveFormFieldElementAction(Request $request)
  108.     {
  109.         $action = new RetrieveFormFieldElementAction($this->twig$this->pool$this->helper);
  110.         return $action($request);
  111.     }
  112.     /**
  113.      * @throws NotFoundHttpException|\RuntimeException
  114.      *
  115.      * @return Response
  116.      */
  117.     public function getShortObjectDescriptionAction(Request $request)
  118.     {
  119.         $action = new GetShortObjectDescriptionAction($this->twig$this->pool);
  120.         return $action($request);
  121.     }
  122.     /**
  123.      * @return Response
  124.      */
  125.     public function setObjectFieldValueAction(Request $request)
  126.     {
  127.         $action = new SetObjectFieldValueAction($this->twig$this->pool$this->validator$this->resolver);
  128.         return $action($request);
  129.     }
  130.     /**
  131.      * Retrieve list of items for autocomplete form field.
  132.      *
  133.      * @throws \RuntimeException
  134.      * @throws AccessDeniedException
  135.      *
  136.      * @return JsonResponse
  137.      */
  138.     public function retrieveAutocompleteItemsAction(Request $request)
  139.     {
  140.         $action = new RetrieveAutocompleteItemsAction($this->pool);
  141.         return $action($request);
  142.     }
  143. }