vendor/alterphp/easyadmin-extension-bundle/src/Controller/AdminController.php line 9

Open in your IDE?
  1. <?php
  2. namespace AlterPHP\EasyAdminExtensionBundle\Controller;
  3. use EasyCorp\Bundle\EasyAdminBundle\Controller\AdminController as BaseAdminController;
  4. use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents;
  5. use Symfony\Component\HttpFoundation\JsonResponse;
  6. class AdminController extends BaseAdminController
  7. {
  8.     protected function embeddedListAction()
  9.     {
  10.         $this->dispatch(EasyAdminEvents::PRE_LIST);
  11.         $fields $this->entity['list']['fields'];
  12.         $paginator $this->findAll($this->entity['class'], $this->request->query->get('page'1), $this->config['list']['max_results'], $this->request->query->get('sortField'), $this->request->query->get('sortDirection'));
  13.         $this->dispatch(EasyAdminEvents::POST_LIST, array('paginator' => $paginator));
  14.         return $this->render('@EasyAdminExtension/default/embedded_list.html.twig', array(
  15.             'paginator' => $paginator,
  16.             'fields' => $fields,
  17.             'masterRequest' => $this->get('request_stack')->getMasterRequest(),
  18.         ));
  19.     }
  20.     /**
  21.      * {@inheritdoc}
  22.      *
  23.      * @throws \Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException
  24.      */
  25.     protected function isActionAllowed($actionName)
  26.     {
  27.         switch ($actionName) {
  28.             // autocomplete action is mapped to list action for access permissions
  29.             case 'autocomplete':
  30.             // embeddedList action is mapped to list action for access permissions
  31.             case 'embeddedList':
  32.                 $actionName 'list';
  33.                 break;
  34.             // newAjax action is mapped to new action for access permissions
  35.             case 'newAjax':
  36.                 $actionName 'new';
  37.                 break;
  38.             default:
  39.                 break;
  40.         }
  41.         // Get item for edit/show or custom actions => security voters may apply
  42.         $easyadmin $this->request->attributes->get('easyadmin');
  43.         $subject $easyadmin['item'] ?? null;
  44.         $this->get('alterphp.easyadmin_extension.admin_authorization_checker')->checksUserAccess(
  45.             $this->entity$actionName$subject
  46.         );
  47.         return parent::isActionAllowed($actionName);
  48.     }
  49.     /**
  50.      * The method that is executed when the user performs a 'new ajax' action on an entity.
  51.      *
  52.      * @return JsonResponse
  53.      */
  54.     protected function newAjaxAction()
  55.     {
  56.         $this->dispatch(EasyAdminEvents::PRE_NEW);
  57.         $entity $this->executeDynamicMethod('createNew<EntityName>Entity');
  58.         $easyadmin = \array_merge($this->request->attributes->get('easyadmin'), array('item' => $entity));
  59.         $this->request->attributes->set('easyadmin'$easyadmin);
  60.         $fields $this->entity['new']['fields'];
  61.         $newForm $this->executeDynamicMethod('create<EntityName>NewForm', [$entity$fields]);
  62.         $newForm->handleRequest($this->request);
  63.         if ($newForm->isSubmitted() && $newForm->isValid()) {
  64.             $this->dispatch(EasyAdminEvents::PRE_PERSIST, ['entity' => $entity]);
  65.             $this->executeDynamicMethod('persist<EntityName>Entity', [$entity]);
  66.             $this->dispatch(EasyAdminEvents::POST_PERSIST, ['entity' => $entity]);
  67.             return new JsonResponse(['option' => ['id' => $entity->getId(), 'text' => (string) $entity]]);
  68.         }
  69.         $this->dispatch(EasyAdminEvents::POST_NEW, ['entity_fields' => $fields'form' => $newForm'entity' => $entity]);
  70.         $parameters = ['form' => $newForm->createView(), 'entity_fields' => $fields'entity' => $entity];
  71.         $templatePath '@EasyAdminExtension/default/new_ajax.html.twig';
  72.         if (isset($this->entity['templates']['new_ajax'])) {
  73.             $templatePath $this->entity['templates']['new_ajax'];
  74.         }
  75.         return new JsonResponse(['html' => $this->renderView($templatePath$parameters)]);
  76.     }
  77. }