src/Controller/FormAdminController.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Form;
  4. use App\Service\CsvExporter;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Sonata\AdminBundle\Controller\CRUDController;
  7. class FormAdminController extends CRUDController
  8. {
  9.     /**
  10.      * @var CsvExporter
  11.      */
  12.     private $csvExporter;
  13.     public function __construct(CsvExporter $csvExporter)
  14.    {
  15.        $this->csvExporter $csvExporter;
  16.    }
  17.     /**
  18.      * @param $id
  19.      * @return \Symfony\Component\HttpFoundation\StreamedResponse
  20.      */
  21.     public function customExportAction($id)
  22.     {
  23.         /** @var Form $object */
  24.         $object $this->admin->getObject($id);
  25.         $entities = new ArrayCollection($object->getFormInputs()->toArray());
  26.         return $this->csvExporter->export($entities$object->getEvent()->getName());
  27.     }
  28. }