1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* (c) FSi sp. z o.o. <[email protected]> |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace FSi\Bundle\AdminBundle\Admin\CRUD\Context; |
13
|
|
|
|
14
|
|
|
use FSi\Bundle\AdminBundle\Admin\Context\ContextAbstract; |
15
|
|
|
use FSi\Bundle\AdminBundle\Admin\CRUD\ListElement; |
16
|
|
|
use FSi\Bundle\AdminBundle\Admin\Element; |
17
|
|
|
use FSi\Bundle\AdminBundle\Event\AdminEvent; |
18
|
|
|
use FSi\Bundle\AdminBundle\Event\ListEvent; |
19
|
|
|
use FSi\Component\DataGrid\DataGridInterface; |
20
|
|
|
use FSi\Component\DataSource\DataSourceInterface; |
21
|
|
|
use Symfony\Component\HttpFoundation\Request; |
22
|
|
|
|
23
|
|
|
class ListElementContext extends ContextAbstract |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var ListElement |
27
|
|
|
*/ |
28
|
|
|
protected $element; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var DataSourceInterface |
32
|
|
|
*/ |
33
|
|
|
protected $dataSource; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var DataGridInterface |
37
|
|
|
*/ |
38
|
|
|
protected $dataGrid; |
39
|
|
|
|
40
|
|
|
public function setElement(Element $element): void |
41
|
|
|
{ |
42
|
|
|
$this->element = $element; |
|
|
|
|
43
|
|
|
$this->dataSource = $this->element->createDataSource(); |
|
|
|
|
44
|
|
|
$this->dataGrid = $this->element->createDataGrid(); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function hasTemplateName(): bool |
48
|
|
|
{ |
49
|
|
|
return $this->element->hasOption('template_list') || parent::hasTemplateName(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getTemplateName(): ?string |
53
|
|
|
{ |
54
|
|
|
return $this->element->hasOption('template_list') |
55
|
|
|
? $this->element->getOption('template_list') |
56
|
|
|
: parent::getTemplateName() |
57
|
|
|
; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function getData(): array |
61
|
|
|
{ |
62
|
|
|
return [ |
63
|
|
|
'datagrid_view' => $this->dataGrid->createView(), |
64
|
|
|
'datasource_view' => $this->dataSource->createView(), |
65
|
|
|
'element' => $this->element, |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
protected function createEvent(Request $request): AdminEvent |
70
|
|
|
{ |
71
|
|
|
return new ListEvent($this->element, $request, $this->dataSource, $this->dataGrid); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
protected function getSupportedRoute(): string |
75
|
|
|
{ |
76
|
|
|
return 'fsi_admin_list'; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
protected function supportsElement(Element $element): bool |
80
|
|
|
{ |
81
|
|
|
return $element instanceof ListElement; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.