1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Alpixel\Bundle\MenuBundle\Controller; |
4
|
|
|
|
5
|
|
|
use Alpixel\Bundle\MenuBundle\Entity\Item; |
6
|
|
|
use Alpixel\Bundle\MenuBundle\Entity\Menu; |
7
|
|
|
use Pix\SortableBehaviorBundle\Controller\SortableAdminController as Controller; |
8
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
9
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
10
|
|
|
|
11
|
|
|
class CRUDController extends Controller |
12
|
|
|
{ |
13
|
|
|
public function itemAction() |
14
|
|
|
{ |
15
|
|
|
$object = $this->admin->getSubject(); |
16
|
|
|
$router = $this->container->get('router'); |
17
|
|
|
$parameters = []; |
18
|
|
|
|
19
|
|
|
if ($object instanceof Menu) { |
20
|
|
|
$parameters['menu'] = $object->getId(); |
21
|
|
|
} elseif ($object instanceof Item) { |
22
|
|
|
$parameters['menu'] = $object->getMenu()->getId(); |
23
|
|
|
$parameters['item'] = $object->getId(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
$url = $router->generate('admin_alpixel_menu_item_list', $parameters, UrlGeneratorInterface::ABSOLUTE_PATH); |
27
|
|
|
|
28
|
|
|
return new RedirectResponse($url); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
protected function redirectTo($object) |
32
|
|
|
{ |
33
|
|
|
$request = $this->getRequest(); |
34
|
|
|
|
35
|
|
|
$url = false; |
36
|
|
|
$params = []; |
37
|
|
|
|
38
|
|
|
if ($object instanceof Item) { |
39
|
|
|
if ($object->getParent() !== null) { |
40
|
|
|
$itemId = $object->getParent()->getId(); |
41
|
|
|
$params['list']['item'] = $itemId; |
42
|
|
|
$params['create']['create-item'] = $itemId; |
43
|
|
|
} |
44
|
|
|
$menuId = $object->getMenu()->getId(); |
45
|
|
|
$params['list']['menu'] = $menuId; |
46
|
|
|
$params['create']['create-menu'] = $menuId; |
47
|
|
|
} elseif ($object instanceof Menu) { |
48
|
|
|
$menuId = $object->getId(); |
49
|
|
|
$params['list']['menu'] = $menuId; |
50
|
|
|
$params['create']['create-menu'] = $menuId; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if (null !== $request->get('btn_update_and_list')) { |
54
|
|
|
$url = $this->admin->generateUrl('list', $params['list']); |
55
|
|
|
} elseif (null !== $request->get('btn_create_and_list')) { |
56
|
|
|
$url = $this->admin->generateUrl('list', $params['list']); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if (null !== $request->get('btn_create_and_create')) { |
60
|
|
|
if ($this->admin->hasActiveSubClass()) { |
61
|
|
|
$params['create']['subclass'] = $request->get('subclass'); |
62
|
|
|
} |
63
|
|
|
$url = $this->admin->generateUrl('create', $params['create']); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
if ($this->getRestMethod() === 'DELETE') { |
67
|
|
|
if ($object instanceof Item) { |
68
|
|
|
$url = $this->admin->generateUrl('list', $params['list']); |
69
|
|
|
} |
70
|
|
|
else { |
71
|
|
|
$router = $this->get('router'); |
72
|
|
|
$url= $router->generate('admin_alpixel_menu_menu_list'); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
if (!$url) { |
77
|
|
|
foreach (array('edit', 'show') as $route) { |
78
|
|
|
if ($this->admin->hasRoute($route) && $this->admin->isGranted(strtoupper($route), $object)) { |
79
|
|
|
$url = $this->admin->generateObjectUrl($route, $object); |
80
|
|
|
break; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
if (!$url) { |
86
|
|
|
$router = $this->get('router'); |
87
|
|
|
$url= $router->generate('admin_alpixel_menu_menu_list'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return new RedirectResponse($url); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|