|
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\Display\Context; |
|
13
|
|
|
|
|
14
|
|
|
use FSi\Bundle\AdminBundle\Admin\Context\ContextAbstract; |
|
15
|
|
|
use FSi\Bundle\AdminBundle\Admin\Display\Element as DisplayElement; |
|
16
|
|
|
use FSi\Bundle\AdminBundle\Admin\Element; |
|
17
|
|
|
use FSi\Bundle\AdminBundle\Display\Display; |
|
18
|
|
|
use FSi\Bundle\AdminBundle\Event\AdminEvent; |
|
19
|
|
|
use FSi\Bundle\AdminBundle\Event\DisplayEvent; |
|
20
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
21
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
22
|
|
|
|
|
23
|
|
|
class DisplayContext extends ContextAbstract |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var DisplayElement |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $element; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var Display |
|
32
|
|
|
*/ |
|
33
|
|
|
private $display; |
|
34
|
|
|
|
|
35
|
|
|
public function hasTemplateName(): bool |
|
36
|
|
|
{ |
|
37
|
|
|
return $this->element->hasOption('template') || parent::hasTemplateName(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function getTemplateName(): ?string |
|
41
|
|
|
{ |
|
42
|
|
|
return $this->element->hasOption('template') |
|
43
|
|
|
? $this->element->getOption('template') |
|
44
|
|
|
: parent::getTemplateName() |
|
45
|
|
|
; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function getData(): array |
|
49
|
|
|
{ |
|
50
|
|
|
return [ |
|
51
|
|
|
'display' => $this->display->getData(), |
|
52
|
|
|
'element' => $this->element, |
|
53
|
|
|
]; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function setElement(Element $element): void |
|
57
|
|
|
{ |
|
58
|
|
|
$this->element = $element; |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
protected function createEvent(Request $request): AdminEvent |
|
62
|
|
|
{ |
|
63
|
|
|
$object = $this->getObject($request); |
|
64
|
|
|
$this->display = $this->element->createDisplay($object); |
|
65
|
|
|
|
|
66
|
|
|
return new DisplayEvent($this->element, $request, $this->display, $object); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
protected function getSupportedRoute(): string |
|
70
|
|
|
{ |
|
71
|
|
|
return 'fsi_admin_display'; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
protected function supportsElement(Element $element): bool |
|
75
|
|
|
{ |
|
76
|
|
|
return $element instanceof DisplayElement; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param Request $request |
|
81
|
|
|
* @return mixed |
|
82
|
|
|
*/ |
|
83
|
|
|
private function getObject(Request $request) |
|
84
|
|
|
{ |
|
85
|
|
|
$id = $request->get('id'); |
|
86
|
|
|
|
|
87
|
|
|
$object = $this->element->getDataIndexer()->getData($id); |
|
88
|
|
|
if (!$object) { |
|
89
|
|
|
throw new NotFoundHttpException(sprintf('Can\'t find object with id %s', $id)); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
return $object; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
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.