Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
4 роки тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. <?php
  2. namespace Lc\ShopBundle\Controller\Backend;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Doctrine\ORM\EntityRepository;
  5. use EasyCorp\Bundle\EasyAdminBundle\Controller\EasyAdminController;
  6. use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents;
  7. use FOS\UserBundle\Model\UserManagerInterface;
  8. use Lc\ShopBundle\Context\FilterMultipleMerchantsInterface;
  9. use Lc\ShopBundle\Context\MerchantInterface;
  10. use Lc\ShopBundle\Context\ReminderInterface;
  11. use Lc\ShopBundle\Context\SeoInterface;
  12. use Lc\ShopBundle\Context\StatusInterface;
  13. use Lc\ShopBundle\Context\TreeInterface;
  14. use Lc\ShopBundle\Form\Backend\Common\AbstractEditPositionType;
  15. use Lc\ShopBundle\Form\Backend\Filters\ListFilterType;
  16. use Lc\ShopBundle\Model\User;
  17. use Lc\ShopBundle\Services\UtilsManager;
  18. use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport;
  19. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  20. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  21. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  22. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  23. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  24. use Symfony\Component\Form\Extension\Core\Type\TextType;
  25. use Symfony\Component\Form\FormEvent;
  26. use Symfony\Component\Form\FormEvents;
  27. use Symfony\Component\HttpFoundation\JsonResponse;
  28. use Symfony\Component\HttpFoundation\Response;
  29. use Symfony\Component\Security\Core\Security;
  30. use Symfony\Contracts\Translation\TranslatorInterface;
  31. class AdminController extends EasyAdminController
  32. {
  33. protected $security;
  34. protected $userManager;
  35. protected $em;
  36. protected $utils;
  37. protected $merchantUtils;
  38. protected $mailjetTransport;
  39. protected $orderUtils;
  40. protected $mailUtils ;
  41. protected $translator;
  42. protected $filtersForm = null;
  43. public function __construct(Security $security, UserManagerInterface $userManager, EntityManagerInterface $em,
  44. MailjetTransport $mailjetTransport, UtilsManager $utilsManager, TranslatorInterface $translator)
  45. {
  46. $this->security = $security;
  47. $this->userManager = $userManager;
  48. $this->em = $em;
  49. $this->mailjetTransport = $mailjetTransport;
  50. $this->utils = $utilsManager->getUtils();
  51. $this->merchantUtils = $utilsManager->getMerchantUtils();
  52. $this->orderUtils = $utilsManager->getOrderUtils();;
  53. $this->mailUtils = $utilsManager->getMailUtils() ;
  54. $this->translator = $translator;
  55. }
  56. public function createCustomForm($class, $action, $parameters, $data = true)
  57. {
  58. $options = array();
  59. if ($data) $options['data'] = $parameters['entity'];
  60. $options['action'] = $this->generateUrl('easyadmin', array(
  61. 'action' => $action,
  62. 'entity' => $this->entity['name'],
  63. 'id' => $parameters['entity']->getId()
  64. ));
  65. return $this->createForm($class, null, $options);
  66. }
  67. public function autocompleteAction()
  68. {
  69. $entityName = $this->request->query->get('entity');
  70. $valueSearched = $this->request->query->get('q');
  71. $field = $this->request->query->get('field');
  72. $class = $this->entity['class'];
  73. $repo = $this->em->getRepository($class);
  74. $values = $repo->findByTerm($field, $valueSearched);
  75. $response = array();
  76. foreach ($values as $value) {
  77. $response[] = $value[$field];
  78. }
  79. return new JsonResponse($response);
  80. }
  81. /**
  82. * Réécriture de show action pr rediriger vers l'édition
  83. */
  84. public function showAction()
  85. {
  86. $id = $this->request->query->get('id');
  87. $entity = $this->request->query->get('entity');
  88. return $this->redirectToRoute('easyadmin', [
  89. 'action' => 'edit',
  90. 'entity' => $entity,
  91. 'id' => $id
  92. ]);
  93. }
  94. /**
  95. * Réécriture de removeEntity pour passer les status à -1
  96. */
  97. protected function removeEntity($entity)
  98. {
  99. if ($entity instanceof StatusInterface) {
  100. $entity->setStatus(-1);
  101. $this->em->persist($entity);
  102. $this->em->flush();
  103. } else {
  104. parent::removeEntity($entity);
  105. }
  106. }
  107. protected function commonDqlFilterQueryBuilder($entityClass, $dqlFilter)
  108. {
  109. if ($pos = strpos($dqlFilter, 'currentMerchant')) {
  110. $dqlFilter = sprintf(str_replace('currentMerchant', $this->getUser()->getMerchant()->getId(), $dqlFilter));
  111. }
  112. if (new $entityClass instanceof StatusInterface && strpos($dqlFilter, 'entity.status') === false) {
  113. if ($dqlFilter) $dqlFilter .= sprintf(' AND entity.status > = 0');
  114. else $dqlFilter .= sprintf(' entity.status > = 0');
  115. }
  116. return $dqlFilter;
  117. }
  118. protected function commonQueryFilter($entityClass, $queryBuilder)
  119. {
  120. if (new $entityClass instanceof FilterMultipleMerchantsInterface) {
  121. $queryBuilder->andWhere(':currentMerchant MEMBER OF entity.merchants')
  122. ->setParameter(':currentMerchant', $this->getUser()->getMerchant()->getId());
  123. }
  124. }
  125. protected function createSearchQueryBuilder($entityClass, $searchQuery, array $searchableFields, $sortField = null, $sortDirection = null, $dqlFilter = null)
  126. {
  127. $dqlFilter = $this->commonDqlFilterQueryBuilder($entityClass, $dqlFilter);
  128. $queryBuilder = parent::createSearchQueryBuilder($entityClass, $searchQuery, $searchableFields, $sortField, $sortDirection, $dqlFilter);
  129. $this->commonQueryFilter($entityClass, $queryBuilder);
  130. return $queryBuilder;
  131. }
  132. protected function createListQueryBuilder($entityClass, $sortDirection, $sortField = null, $dqlFilter = null)
  133. {
  134. $dqlFilter = $this->commonDqlFilterQueryBuilder($entityClass, $dqlFilter);
  135. $queryBuilder = parent::createListQueryBuilder($entityClass, $sortDirection, $sortField, $dqlFilter);
  136. $this->commonQueryFilter($entityClass, $queryBuilder);
  137. $listFields = $this->entity['list']['fields'];
  138. $this->filtersForm = $this->createForm(ListFilterType::class, null, array(
  139. 'fields' => $listFields,
  140. 'method' => 'get',
  141. 'entity_name' => $this->entity['name'],
  142. //'entityClass' => $this->entity['class'],
  143. 'entity_class' => $this->entity['class']
  144. ));
  145. $this->filtersForm->handleRequest($this->request);
  146. if ($this->filtersForm->isSubmitted() && $this->filtersForm->isValid()) {
  147. foreach ($listFields as $field) {
  148. if ($this->filtersForm->has($field['property'])) {
  149. switch ($field['dataType']) {
  150. case 'option':
  151. case 'integer':
  152. case 'text':
  153. case 'string':
  154. case 'toggle':
  155. $filter = $this->filtersForm->get($field['property'])->getData();
  156. if ($filter !== null) {
  157. $queryBuilder->andWhere('entity.' . $field['property'] . ' LIKE :' . $field['property'] . '');
  158. $queryBuilder->setParameter($field['property'], '%' . $filter . '%');
  159. }
  160. break;
  161. case 'association' :
  162. $filter = $this->filtersForm->get($field['property'])->getData();
  163. if ($filter !== null) {
  164. if ($field['type_options']['multiple']) {
  165. $queryBuilder->andWhere(':' . $field['property'] . ' MEMBER OF entity.' . $field['property'] . '');
  166. } else {
  167. $queryBuilder->andWhere('entity.' . $field['property'] . ' = :' . $field['property'] . '');
  168. }
  169. $queryBuilder->setParameter($field['property'], $filter);
  170. }
  171. break;
  172. case 'datetime':
  173. case 'date':
  174. $dateStart = $this->filtersForm->get($field['property'])->get('dateStart')->getData();
  175. $dateEnd = $this->filtersForm->get($field['property'])->get('dateEnd')->getData();
  176. if ($dateStart) $queryBuilder->andWhere('entity.' . $field['property'] . ' >= :dateStart')->setParameter('dateStart', $dateStart);
  177. if ($dateEnd) $queryBuilder->andWhere('entity.' . $field['property'] . ' <= :dateEnd')->setParameter('dateEnd', $dateEnd);
  178. }
  179. }
  180. }
  181. }
  182. return $queryBuilder;
  183. }
  184. public function renderTemplate($actionName, $templatePath, array $parameters = [])
  185. {
  186. $reminderRepo = $this->em->getRepository(ReminderInterface::class);
  187. $easyadmin = $this->request->attributes->get('easyadmin');
  188. $entityName = $easyadmin['entity']['name'];
  189. $id = null;
  190. if ($easyadmin['item']) $id = $easyadmin['item']->getId();
  191. $reminders = array('reminders' => $reminderRepo->findByEasyAdminConfig($actionName, $entityName, $id));
  192. if ($actionName == 'list') {
  193. if ($this->filtersForm === null) {
  194. $options['fields'] = $parameters['fields'];
  195. $options['method'] = 'get';
  196. $this->filtersForm = $this->createForm(ListFilterType::class, null, $options);
  197. }
  198. $parameters = array_merge(
  199. $parameters,
  200. array(
  201. 'filters_form' => $this->filtersForm->createView()
  202. )
  203. );
  204. }
  205. $parameters = array_merge(
  206. $parameters,
  207. $this->getTwigExtraParameters(),
  208. $reminders
  209. );
  210. return parent::renderTemplate($actionName, $templatePath, $parameters);
  211. }
  212. public function getTwigExtraParameters()
  213. {
  214. $repositoryMerchant = $this->getDoctrine()->getRepository(MerchantInterface::class);
  215. $merchants = $repositoryMerchant->findAll();
  216. $user = $this->security->getUser();
  217. return [
  218. 'merchants' => $merchants,
  219. 'current_merchant' => ($user && $user->getMerchant()) ? $user->getMerchant() : null,
  220. ];
  221. }
  222. public function listChildrenAction()
  223. {
  224. $this->dispatch(EasyAdminEvents::PRE_LIST);
  225. $id = $this->request->query->get('id');
  226. $this->entity['list']['dql_filter'] = "entity.parent = " . $id;
  227. $easyadmin = $this->request->attributes->get('easyadmin');
  228. $entity = $easyadmin['item'];
  229. $fields = $this->entity['list']['fields'];
  230. $paginator = $this->findAll($this->entity['class'], $this->request->query->get('page', 1), $this->entity['list']['max_results'], $this->request->query->get('sortField'), $this->request->query->get('sortDirection'), $this->entity['list']['dql_filter']);
  231. $this->dispatch(EasyAdminEvents::POST_LIST, ['paginator' => $paginator]);
  232. $parameters = [
  233. 'paginator' => $paginator,
  234. 'fields' => $fields,
  235. 'batch_form' => $this->createBatchForm($this->entity['name'])->createView(),
  236. 'delete_form_template' => $this->createDeleteForm($this->entity['name'], '__id__')->createView(),
  237. 'entity' => $entity,
  238. ];
  239. return $this->executeDynamicMethod('render<EntityName>Template', ['list', $this->entity['templates']['list'], $parameters]);
  240. }
  241. public function sortAction()
  242. {
  243. $this->dispatch(EasyAdminEvents::PRE_LIST);
  244. $entity = null;
  245. //Replace this with query builder function, do not use finAll of easyAdmin
  246. if ($this->request->query->get('id')) {
  247. $id = $this->request->query->get('id');
  248. $this->entity['list']['dql_filter'] = "entity.parent = " . $id;
  249. $easyadmin = $this->request->attributes->get('easyadmin');
  250. $entity = $easyadmin['item'];
  251. }
  252. if ($this->entity['list']['dql_filter']) $this->entity['list']['dql_filter'] .= sprintf(' AND entity.status = 1');
  253. else $this->entity['list']['dql_filter'] .= sprintf(' entity.status = 1');
  254. $fields = $this->entity['list']['fields'];
  255. $paginator = $this->findAll($this->entity['class'], $this->request->query->get('page', 1), 500, $this->request->query->get('sortField'), $this->request->query->get('sortDirection'), $this->entity['list']['dql_filter']);
  256. $this->dispatch(EasyAdminEvents::POST_LIST, ['paginator' => $paginator]);
  257. $positionForm = $this->createFormBuilder(array('entities', $paginator->getCurrentPageResults()))
  258. ->add('entities', CollectionType::class, array(
  259. 'required' => true,
  260. 'allow_add' => true,
  261. 'entry_type' => AbstractEditPositionType::class,
  262. ))
  263. ->getForm();
  264. $positionForm->handleRequest($this->request);
  265. if ($positionForm->isSubmitted() && $positionForm->isValid()) {
  266. $class = $this->entity['class'];
  267. $repo = $this->em->getRepository($class);
  268. $latsPos = 0;
  269. foreach ($positionForm->get('entities')->getData() as $elm) {
  270. $this->dispatch(EasyAdminEvents::PRE_UPDATE, ['entity' => $entity]);
  271. $entity = $repo->find($elm['id']);
  272. $entity->setPosition($elm['position']);
  273. $this->em->persist($entity);
  274. $this->dispatch(EasyAdminEvents::POST_UPDATE, ['entity' => $entity]);
  275. $latsPos = $elm['position'];
  276. }
  277. dump($latsPos);
  278. //die();
  279. //to do récupérer les élements hors ligne et incrémenter position
  280. /*foreach ($repo->findBy(array('status'=> false)) as $offlineEntity) {
  281. $latsPos++;
  282. $offlineEntity->setPosition($latsPos);
  283. $this->em->persist($offlineEntity);
  284. }*/
  285. $this->em->flush();
  286. $this->addFlash('success', 'Position modifié', array(), 'mweb');
  287. return $this->redirectToReferrer();
  288. }
  289. $parameters = [
  290. 'paginator' => $paginator,
  291. 'fields' => $fields,
  292. 'batch_form' => $this->createBatchForm($this->entity['name'])->createView(),
  293. 'delete_form_template' => $this->createDeleteForm($this->entity['name'], '__id__')->createView(),
  294. 'postion_form' => $positionForm->createView(),
  295. 'entity' => $entity,
  296. 'sortable' => true
  297. ];
  298. return $this->executeDynamicMethod('render<EntityName>Template', ['sortable', "@LcShop/backend/default/sortable.html.twig", $parameters]);
  299. }
  300. public function createEntityFormBuilder($entity, $view, $override = true)
  301. {
  302. $formBuilder = parent::createEntityFormBuilder($entity, $view);
  303. if ($override) $formBuilder = $this->overrideFormBuilder($formBuilder, $entity, $view);
  304. return $formBuilder;
  305. }
  306. public function overrideFormBuilder($formBuilder, $entity, $view)
  307. {
  308. $id = (null !== $entity->getId()) ? $entity->getId() : 0;
  309. if ($entity instanceof SeoInterface) {
  310. $formBuilder->add('metaTitle', TextType::class, array(
  311. 'required' => false,
  312. 'translation_domain' => 'lcshop'
  313. )
  314. );
  315. $formBuilder->add('metaDescription', TextareaType::class, array(
  316. 'required' => false,
  317. 'translation_domain' => 'lcshop'
  318. )
  319. );
  320. /*$formBuilder->add('oldUrls', TextareaType::class, array(
  321. 'required' => false,
  322. 'translation_domain' => 'lcshop'
  323. )
  324. );*/
  325. }
  326. if ($entity instanceof StatusInterface) {
  327. $formBuilder->add('status', ChoiceType::class, array(
  328. 'choices' => array(
  329. 'field.default.statusOptions.offline' => '0',
  330. 'field.default.statusOptions.online' => '1'
  331. ),
  332. 'expanded' => true,
  333. 'required' => true,
  334. 'translation_domain' => 'lcshop'
  335. )
  336. );
  337. }
  338. if ($entity instanceof TreeInterface) {
  339. $formBuilder->add('parent', EntityType::class, array(
  340. 'class' => $this->entity['class'],
  341. 'query_builder' => function (EntityRepository $repo) use ($id) {
  342. return $repo->createQueryBuilder('e')
  343. ->where('e.parent is NULL')
  344. ->andWhere('e.status >= 0')
  345. ->orderBy('e.status', "DESC");
  346. },
  347. 'required' => false,
  348. )
  349. );
  350. }
  351. $formBuilder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) {
  352. $form = $event->getForm();
  353. $childrens = $form->all();
  354. $this->loopFormField($form, $childrens);
  355. });
  356. return $formBuilder;
  357. }
  358. private function loopFormField($form, $childrens)
  359. {
  360. foreach ($childrens as $child) {
  361. $statusInterface = false;
  362. $treeInterface = false;
  363. $type = $child->getConfig()->getType()->getInnerType();;
  364. if ($type instanceof EntityType) {
  365. $passedOptions = $child->getConfig()->getOptions();
  366. $classImplements = class_implements($passedOptions['class']);
  367. $isFilterMerchantInterface = in_array('Lc\ShopBundle\Context\FilterMerchantInterface', $classImplements);
  368. $isFilterMultipleMerchantsInterface = in_array('Lc\ShopBundle\Context\FilterMultipleMerchantsInterface', $classImplements);
  369. if ($isFilterMerchantInterface || $isFilterMultipleMerchantsInterface) {
  370. if (in_array('Lc\ShopBundle\Context\StatusInterface', $classImplements)) {
  371. $statusInterface = true;
  372. }
  373. if (in_array('Lc\ShopBundle\Context\TreeInterface', $classImplements)) {
  374. $treeInterface = true;
  375. }
  376. $propertyMerchant = 'merchant';
  377. if ($isFilterMultipleMerchantsInterface) {
  378. $propertyMerchant .= 's';
  379. }
  380. $form->add($child->getName(), EntityType::class, array(
  381. 'class' => $this->em->getClassMetadata($passedOptions['class'])->getName(),
  382. 'label' => $passedOptions['label'],
  383. 'multiple' => isset($passedOptions['multiple']) ? $passedOptions['multiple'] : false,
  384. 'placeholder' => '--',
  385. 'translation_domain' => 'lcshop',
  386. 'query_builder' => function (EntityRepository $repo) use ($passedOptions, $propertyMerchant, $statusInterface, $treeInterface, $child) {
  387. $queryBuilder = $repo->createQueryBuilder('e');
  388. $propertyMerchant = 'e.' . $propertyMerchant;
  389. if ($passedOptions['class'] == 'App\Entity\PointSale') {
  390. $queryBuilder->where(':currentMerchant MEMBER OF ' . $propertyMerchant);
  391. } else {
  392. $queryBuilder->where($propertyMerchant . ' = :currentMerchant');
  393. }
  394. if ($statusInterface) {
  395. $queryBuilder->andWhere('e.status >= 0');
  396. }
  397. if ($treeInterface && $child->getName() == 'parent') {
  398. $queryBuilder->andWhere('e.parent is null');
  399. }
  400. $queryBuilder->setParameter(':currentMerchant', $this->getUser()->getMerchant()->getId());
  401. return $queryBuilder;
  402. },
  403. 'choice_label' => function ($choice) {
  404. if ($choice instanceof StatusInterface && $choice->getStatus() == 0) {
  405. return $choice . ' [hors ligne]';
  406. }
  407. return $choice;
  408. },
  409. 'required' => $passedOptions['required'],
  410. 'choice_attr' => $passedOptions['choice_attr'],
  411. )
  412. );
  413. }
  414. } else {
  415. $subChildrens = $child->all();
  416. if (count($subChildrens)) {
  417. $this->loopFormField($child, $subChildrens);
  418. }
  419. }
  420. }
  421. }
  422. protected function editAction()
  423. {
  424. $this->dispatch(EasyAdminEvents::PRE_EDIT);
  425. $id = $this->request->query->get('id');
  426. $easyadmin = $this->request->attributes->get('easyadmin');
  427. $entity = $easyadmin['item'];
  428. if ($this->request->isXmlHttpRequest() && $property = $this->request->query->get('property')) {
  429. $newValue = 'true' === mb_strtolower($this->request->query->get('newValue'));
  430. $fieldsMetadata = $this->entity['list']['fields'];
  431. if (!isset($fieldsMetadata[$property]) || 'toggle' !== $fieldsMetadata[$property]['dataType']) {
  432. throw new \RuntimeException(sprintf('The type of the "%s" property is not "toggle".', $property));
  433. }
  434. $this->updateEntityProperty($entity, $property, $newValue);
  435. $this->utils->addFlash('success', 'success.common.fieldChange');
  436. $response['flashMessages'] = $this->utils->getFlashMessages();
  437. return new Response(json_encode($response));
  438. }
  439. $fields = $this->entity['edit']['fields'];
  440. $editForm = $this->executeDynamicMethod('create<EntityName>EditForm', [$entity, $fields]);
  441. $deleteForm = $this->createDeleteForm($this->entity['name'], $id);
  442. $editForm->handleRequest($this->request);
  443. if ($editForm->isSubmitted() && $editForm->isValid()) {
  444. $this->processUploadedFiles($editForm);
  445. $this->dispatch(EasyAdminEvents::PRE_UPDATE, ['entity' => $entity]);
  446. $this->executeDynamicMethod('update<EntityName>Entity', [$entity, $editForm]);
  447. $this->dispatch(EasyAdminEvents::POST_UPDATE, ['entity' => $entity]);
  448. return $this->redirectToReferrer();
  449. }
  450. $this->dispatch(EasyAdminEvents::POST_EDIT);
  451. $parameters = [
  452. 'form' => $editForm->createView(),
  453. 'entity_fields' => $fields,
  454. 'entity' => $entity,
  455. 'delete_form' => $deleteForm->createView(),
  456. ];
  457. return $this->executeDynamicMethod('render<EntityName>Template', ['edit', $this->entity['templates']['edit'], $parameters]);
  458. }
  459. /* public function createNewEntity(){
  460. $idDuplicate = $this->request->query->get('duplicate', null);
  461. if($idDuplicate){
  462. $easyadmin = $this->request->attributes->get('easyadmin');
  463. $entity= $this->em->getRepository($easyadmin['entity']['class'])->find($idDuplicate);
  464. $newProductFamily = clone $entity ;
  465. $this->em->persist($newProductFamily) ;
  466. $this->em->flush() ;
  467. }else{
  468. $entityFullyQualifiedClassName = $this->entity['class'];
  469. return new $entityFullyQualifiedClassName();
  470. }
  471. }*/
  472. public function duplicateAction(){
  473. $id = $this->request->query->get('id');
  474. $refererUrl = $this->request->query->get('referer', '');
  475. $easyadmin = $this->request->attributes->get('easyadmin');
  476. $entity= $this->em->getRepository($easyadmin['entity']['class'])->find($id);
  477. $newEntity = clone $entity ;
  478. $this->em->persist($newEntity) ;
  479. $this->em->flush() ;
  480. return $this->redirectToRoute('easyadmin', ['entity' => $easyadmin['entity']['name'], 'action' => 'edit', 'id' =>$newEntity->getId(), 'referer' =>$refererUrl ]) ;
  481. }
  482. }