src/Controller/Admin/CkeditorAdminController.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Admin;
  3. use Sonata\AdminBundle\Controller\CRUDController;
  4. use Symfony\Component\Form\FormRenderer;
  5. use Symfony\Component\Form\FormView;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  9. use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  10. use WAM\Bundle\MediaBundle\Manager\Interfaces\FileManagerInterface;
  11. final class CkeditorAdminController extends CRUDController
  12. {
  13.     private FileManagerInterface $fileManager;
  14.     /**
  15.      * CkeditorAdminController constructor.
  16.      * @param FileManagerInterface $fileManager
  17.      */
  18.     public function __construct(FileManagerInterface $fileManager)
  19.     {
  20.         $this->fileManager $fileManager;
  21.     }
  22.     /**
  23.      * @throws AccessDeniedException
  24.      */
  25.     public function browserAction(Request $request): Response
  26.     {
  27.         $this->admin->checkAccess('list');
  28.         $datagrid $this->admin->getDatagrid();
  29.         $datagrid->setValue('providerName'null$this->admin->getPersistentParameter('provider'));
  30.         $formView $datagrid->getForm()->createView();
  31.         $this->setFormTheme($formView$this->admin->getFilterTheme());
  32.         return $this->renderWithExtraParams('extensions/ckeditor/browser.html.twig', [
  33.             'action' => 'browser',
  34.             'form' => $formView,
  35.             'datagrid' => $datagrid,
  36.         ]);
  37.     }
  38.     /**
  39.      * @throws AccessDeniedException
  40.      * @throws NotFoundHttpException
  41.      */
  42.     public function uploadAction(Request $request): Response
  43.     {
  44.         $this->admin->checkAccess('create');
  45.         $files $this->fileManager->createFromRequest($request);
  46.         if (!$request->isMethod('POST') || [] === $files) {
  47.             throw $this->createNotFoundException();
  48.         }
  49.         $media $files[0];
  50.         $this->fileManager->processAndSave($media);
  51.         return $this->renderWithExtraParams('extensions/ckeditor/upload.html.twig', [
  52.             'action' => 'list',
  53.             'object' => $media,
  54.         ]);
  55.     }
  56.     /**
  57.      * Sets the admin form theme to form view. Used for compatibility between Symfony versions.
  58.      */
  59.     private function setFormTheme(FormView $formView, array $theme): void
  60.     {
  61.         $this->get('twig')->getRuntime(FormRenderer::class)->setTheme($formView$theme);
  62.     }
  63. }