|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Alpixel\Bundle\CMSBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Sonata\AdminBundle\Controller\CRUDController as Controller; |
|
6
|
|
|
use Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException; |
|
7
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
9
|
|
|
|
|
10
|
|
|
class AdminNodeController extends Controller |
|
11
|
|
|
{ |
|
12
|
|
|
public function createTranslationAction(Request $request) |
|
13
|
|
|
{ |
|
14
|
|
|
$object = $this->admin->getSubject(); |
|
15
|
|
|
$locale = $request->query->get('locale'); |
|
16
|
|
|
|
|
17
|
|
|
if ($locale === null || $object === null) { |
|
18
|
|
|
return $this->createNotFoundException(); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
$entityManager = $this->get('doctrine.orm.entity_manager'); |
|
22
|
|
|
$translation = $entityManager->getRepository('AlpixelCMSBundle:Node') |
|
23
|
|
|
->findTranslation($object, $locale); |
|
24
|
|
|
|
|
25
|
|
|
if ($translation !== null) { |
|
26
|
|
|
return $this->redirect($this->admin->generateUrl('edit', ['id' => $translation->getId()])); |
|
27
|
|
|
} else { |
|
28
|
|
|
$translatedContent = $this->get('alpixel_cms.helper.cms')->createTranslation($object, $locale); |
|
29
|
|
|
$entityManager->persist($translatedContent); |
|
30
|
|
|
$entityManager->flush(); |
|
31
|
|
|
|
|
32
|
|
|
return $this->redirect($this->admin->generateUrl('edit', ['id' => $translatedContent->getId()])); |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function seeAction(Request $request) |
|
|
|
|
|
|
37
|
|
|
{ |
|
38
|
|
|
$object = $this->admin->getSubject(); |
|
39
|
|
|
$contentTypes = $this->admin->getCMSTypes(); |
|
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
foreach ($contentTypes as $key => $contentType) { |
|
42
|
|
|
if ($key === $object->getType()) { |
|
43
|
|
|
if (isset($contentTypes['controller'])) { |
|
44
|
|
|
return $this->redirectToRoute('alpixel_cms', ['slug' => $object->getSlug()]); |
|
45
|
|
|
} elseif ($contentType['admin'] !== null && $contentType['admin']->showCustomURL($object) !== null) { |
|
46
|
|
|
return $this->redirect($contentType['admin']->showCustomURL($object)); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
$this->get('session')->getFlashBag()->add('warning', 'Impossible de trouver une adresse pour cette page'); |
|
52
|
|
|
|
|
53
|
|
|
return $this->redirectTo($object); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function listAction(Request $request = null) |
|
57
|
|
|
{ |
|
58
|
|
|
if (false === $this->admin->isGranted('LIST')) { |
|
59
|
|
|
throw new AccessDeniedException(); |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
$datagrid = $this->admin->getDatagrid(); |
|
63
|
|
|
$formView = $datagrid->getForm()->createView(); |
|
64
|
|
|
|
|
65
|
|
|
if (!$this->container->hasParameter('alpixel_cms.content_types')) { |
|
66
|
|
|
throw $this->createNotFoundException('alpixel_cms.content_types parameters has not been not found, maybe you must be configured cms.yml file'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$cmsContentType = $this->container->getParameter('alpixel_cms.content_types'); |
|
70
|
|
|
$this->get('twig')->getExtension('form')->renderer->setTheme($formView, $this->admin->getFilterTheme()); |
|
71
|
|
|
|
|
72
|
|
|
return $this->render($this->admin->getTemplate('list'), [ |
|
73
|
|
|
'action' => 'list', |
|
74
|
|
|
'cmsContentType' => $cmsContentType, |
|
75
|
|
|
'form' => $formView, |
|
76
|
|
|
'datagrid' => $datagrid, |
|
77
|
|
|
'csrf_token' => $this->getCsrfToken('sonata.batch'), |
|
78
|
|
|
], null, $request); |
|
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* {@inheritdoc} |
|
83
|
|
|
*/ |
|
84
|
|
View Code Duplication |
protected function redirectTo($object) |
|
|
|
|
|
|
85
|
|
|
{ |
|
86
|
|
|
$request = $this->getRequest(); |
|
87
|
|
|
|
|
88
|
|
|
$url = $backToNodeList = false; |
|
89
|
|
|
$instanceAdmin = $this->admin->getConfigurationPool()->getInstance('alpixel_cms.admin.node'); |
|
90
|
|
|
|
|
91
|
|
|
if (null !== $request->get('btn_update_and_list') || null !== $request->get('btn_create_and_list')) { |
|
92
|
|
|
$backToNodeList = true; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
if (null !== $request->get('btn_create_and_create')) { |
|
96
|
|
|
$params = []; |
|
97
|
|
|
if ($this->admin->hasActiveSubClass()) { |
|
98
|
|
|
$params['subclass'] = $request->get('subclass'); |
|
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
$url = $this->admin->generateUrl('create', $params); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
if ($this->getRestMethod() === 'DELETE') { |
|
104
|
|
|
$backToNodeList = true; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
if (!$url) { |
|
|
|
|
|
|
108
|
|
|
foreach (['edit', 'show'] as $route) { |
|
109
|
|
|
if ($this->admin->hasRoute($route) && $this->admin->isGranted(strtoupper($route), $object)) { |
|
110
|
|
|
$url = $this->admin->generateObjectUrl($route, $object); |
|
111
|
|
|
break; |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
if ($backToNodeList || !$url) { |
|
|
|
|
|
|
117
|
|
|
$url = $instanceAdmin->generateUrl('list'); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
return new RedirectResponse($url); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.