src/Controller/DefaultController.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Services\ConsentApiService;
  4. use Pimcore\Controller\FrontendController;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  7. class DefaultController extends FrontendController
  8. {
  9.     /**
  10.      * @param ConsentApiService $consentApi
  11.      */
  12.     public function __construct(
  13.         private ConsentApiService $consentApi
  14.     )
  15.     {
  16.     }
  17.     /**
  18.      * @Template
  19.      * @param Request $request
  20.      * @return array
  21.      */
  22.     public function defaultAction(Request $request)
  23.     {
  24.         $documentId $request->get('realDocument') ?: null;
  25.         $blogPostId $request->get('blogPostId') ?: null;
  26.         $shouldFetchConsentData =
  27.             $request->get('routeDocument')?->getDocument()->getProperty('fetch_terms_and_conditions');
  28.         if ($documentId) {
  29.             return ['realDocument' => $documentId];
  30.         }
  31.         if ($blogPostId) {
  32.             return ['blogPostId' => $blogPostId,];
  33.         }
  34.         if ($shouldFetchConsentData) {
  35.             $consentName $request->get('contentDocument')?->getEditables()['privola_name']->getData();
  36.             if (empty($consentName)) {
  37.                 return [];
  38.             }
  39.             $language $request->getLocale();
  40.             $consentData $this->consentApi->getConsentData($consentName$language);
  41.             if (array_key_exists('errors'$consentData)) {
  42.                 return [];
  43.             }
  44.             return ['fetchData' => $consentData['data']];
  45.         }
  46.         return [];
  47.     }
  48. }