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\Action; |
15
|
|
|
|
16
|
|
|
use Sonata\AdminBundle\Admin\BreadcrumbsBuilderInterface; |
17
|
|
|
use Sonata\AdminBundle\Admin\Pool; |
18
|
|
|
use Sonata\AdminBundle\Templating\TemplateRegistryInterface; |
19
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
20
|
|
|
use Symfony\Component\HttpFoundation\Request; |
21
|
|
|
|
22
|
|
|
final class DashboardAction extends Controller |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
private $dashboardBlocks; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var BreadcrumbsBuilderInterface |
31
|
|
|
*/ |
32
|
|
|
private $breadcrumbsBuilder; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var TemplateRegistryInterface |
36
|
|
|
*/ |
37
|
|
|
private $templateRegistry; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var Pool |
41
|
|
|
*/ |
42
|
|
|
private $pool; |
43
|
|
|
|
44
|
|
|
public function __construct( |
45
|
|
|
array $dashboardBlocks, |
46
|
|
|
BreadcrumbsBuilderInterface $breadcrumbsBuilder, |
47
|
|
|
TemplateRegistryInterface $templateRegistry, |
48
|
|
|
Pool $pool |
49
|
|
|
) { |
50
|
|
|
$this->dashboardBlocks = $dashboardBlocks; |
51
|
|
|
$this->breadcrumbsBuilder = $breadcrumbsBuilder; |
52
|
|
|
$this->templateRegistry = $templateRegistry; |
53
|
|
|
$this->pool = $pool; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function __invoke(Request $request) |
57
|
|
|
{ |
58
|
|
|
$blocks = [ |
59
|
|
|
'top' => [], |
60
|
|
|
'left' => [], |
61
|
|
|
'center' => [], |
62
|
|
|
'right' => [], |
63
|
|
|
'bottom' => [], |
64
|
|
|
]; |
65
|
|
|
|
66
|
|
|
foreach ($this->dashboardBlocks as $block) { |
67
|
|
|
$blocks[$block['position']][] = $block; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$parameters = [ |
71
|
|
|
'base_template' => $request->isXmlHttpRequest() ? |
72
|
|
|
$this->templateRegistry->getTemplate('ajax') : |
73
|
|
|
$this->templateRegistry->getTemplate('layout'), |
74
|
|
|
'admin_pool' => $this->pool, |
75
|
|
|
'blocks' => $blocks, |
76
|
|
|
]; |
77
|
|
|
|
78
|
|
|
if (!$request->isXmlHttpRequest()) { |
79
|
|
|
$parameters['breadcrumbs_builder'] = $this->breadcrumbsBuilder; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return $this->render($this->templateRegistry->getTemplate('dashboard'), $parameters); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|