|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Sonata Project package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Sonata\AdminBundle\Controller; |
|
15
|
|
|
|
|
16
|
|
|
// NEXT_MAJOR: remove this file |
|
17
|
|
|
|
|
18
|
|
|
@trigger_error(sprintf( |
|
|
|
|
|
|
19
|
|
|
'The %1$s\CoreController class is deprecated since version 3.36 and will be removed in 4.0.' |
|
20
|
|
|
.' Use %1$s\SearchAction or %1$s\DashboardAction instead.', |
|
21
|
|
|
__NAMESPACE__ |
|
22
|
|
|
), E_USER_DEPRECATED); |
|
23
|
|
|
|
|
24
|
|
|
use Sonata\AdminBundle\Action\DashboardAction; |
|
25
|
|
|
use Sonata\AdminBundle\Action\SearchAction; |
|
26
|
|
|
use Sonata\AdminBundle\Admin\Pool; |
|
27
|
|
|
use Sonata\AdminBundle\Search\SearchHandler; |
|
28
|
|
|
use Sonata\AdminBundle\Templating\TemplateRegistryInterface; |
|
29
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
30
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
31
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
32
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @author Thomas Rabaix <[email protected]> |
|
36
|
|
|
*/ |
|
37
|
|
|
class CoreController extends Controller |
|
|
|
|
|
|
38
|
|
|
{ |
|
39
|
|
|
/** |
|
40
|
|
|
* @return Response |
|
41
|
|
|
*/ |
|
42
|
|
|
public function dashboardAction() |
|
43
|
|
|
{ |
|
44
|
|
|
$dashboardAction = $this->container->get(DashboardAction::class); |
|
45
|
|
|
|
|
46
|
|
|
return $dashboardAction($this->getCurrentRequest()); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* The search action first render an empty page, if the query is set, then the template generates |
|
51
|
|
|
* some ajax request to retrieve results for each admin. The Ajax query returns a JSON response. |
|
52
|
|
|
* |
|
53
|
|
|
* @throws \RuntimeException |
|
54
|
|
|
* |
|
55
|
|
|
* @return JsonResponse|Response |
|
56
|
|
|
*/ |
|
57
|
|
|
public function searchAction(Request $request) |
|
58
|
|
|
{ |
|
59
|
|
|
$searchAction = $this->container->get(SearchAction::class); |
|
60
|
|
|
|
|
61
|
|
|
return $searchAction($request); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Get the request object from the container. |
|
66
|
|
|
* |
|
67
|
|
|
* This method is compatible with both Symfony 2.3 and Symfony 3 |
|
68
|
|
|
* |
|
69
|
|
|
* NEXT_MAJOR: remove this method. |
|
70
|
|
|
* |
|
71
|
|
|
* @deprecated since sonata-project/admin-bundle 3.0, to be removed in 4.0 and action methods will be adjusted. |
|
72
|
|
|
* Use Symfony\Component\HttpFoundation\Request as an action argument |
|
73
|
|
|
* |
|
74
|
|
|
* @return Request |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getRequest() |
|
77
|
|
|
{ |
|
78
|
|
|
@trigger_error(sprintf( |
|
|
|
|
|
|
79
|
|
|
'The %s method is deprecated since 3.0 and will be removed in 4.0.' |
|
80
|
|
|
.' Inject the %s into the actions instead.', |
|
81
|
|
|
__METHOD__, |
|
82
|
|
|
Request::class |
|
83
|
|
|
), E_USER_DEPRECATED); |
|
84
|
|
|
|
|
85
|
|
|
return $this->getCurrentRequest(); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @return Pool |
|
90
|
|
|
*/ |
|
91
|
|
|
protected function getAdminPool() |
|
92
|
|
|
{ |
|
93
|
|
|
$pool = $this->container->get('sonata.admin.pool'); |
|
94
|
|
|
\assert($pool instanceof Pool); |
|
95
|
|
|
|
|
96
|
|
|
return $pool; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @return SearchHandler |
|
101
|
|
|
*/ |
|
102
|
|
|
protected function getSearchHandler() |
|
103
|
|
|
{ |
|
104
|
|
|
$searchHandler = $this->get('sonata.admin.search.handler'); |
|
105
|
|
|
\assert($searchHandler instanceof SearchHandler); |
|
106
|
|
|
|
|
107
|
|
|
return $searchHandler; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @return string |
|
112
|
|
|
*/ |
|
113
|
|
|
protected function getBaseTemplate() |
|
114
|
|
|
{ |
|
115
|
|
|
if ($this->getCurrentRequest()->isXmlHttpRequest()) { |
|
116
|
|
|
return $this->getTemplateRegistry()->getTemplate('ajax'); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
return $this->getTemplateRegistry()->getTemplate('layout'); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
private function getTemplateRegistry(): TemplateRegistryInterface |
|
123
|
|
|
{ |
|
124
|
|
|
$templateRegistry = $this->container->get('sonata.admin.global_template_registry'); |
|
125
|
|
|
\assert($templateRegistry instanceof TemplateRegistryInterface); |
|
126
|
|
|
|
|
127
|
|
|
return $templateRegistry; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
private function getCurrentRequest(): Request |
|
131
|
|
|
{ |
|
132
|
|
|
return $this->container->get('request_stack')->getCurrentRequest(); |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: