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
|
|
|
namespace FSi\Bundle\AdminBundle\Admin; |
11
|
|
|
|
12
|
|
|
use FSi\Bundle\AdminBundle\Admin\CRUD\DataIndexerElement; |
13
|
|
|
use FSi\Component\DataIndexer\DataIndexerInterface; |
14
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
15
|
|
|
|
16
|
|
|
trait DependentElementImpl |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var RequestStack |
20
|
|
|
*/ |
21
|
|
|
private $requestStack; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var Element |
25
|
|
|
*/ |
26
|
|
|
private $parentElement; |
27
|
|
|
|
28
|
|
|
public function setParentElement(Element $element) |
29
|
|
|
{ |
30
|
|
|
$this->parentElement = $element; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @return Element |
35
|
|
|
*/ |
36
|
|
|
public function getParentElement() |
37
|
|
|
{ |
38
|
|
|
return $this->parentElement; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function setRequestStack(RequestStack $requestStack) |
42
|
|
|
{ |
43
|
|
|
$this->requestStack = $requestStack; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return object|null |
48
|
|
|
*/ |
49
|
|
|
public function getParentObject() |
50
|
|
|
{ |
51
|
|
|
$dataIndexer = $this->getParentDataIndexer(); |
52
|
|
|
$parentObjectId = $this->getParentObjectId(); |
53
|
|
|
|
54
|
|
|
if ($dataIndexer !== null && $parentObjectId !== null) { |
55
|
|
|
return $dataIndexer->getData($parentObjectId); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return null; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return string|null |
63
|
|
|
*/ |
64
|
|
|
protected function getParentObjectId() |
65
|
|
|
{ |
66
|
|
|
$currentRequest = $this->requestStack->getCurrentRequest(); |
67
|
|
|
|
68
|
|
|
if ($currentRequest === null) { |
69
|
|
|
return null; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $currentRequest->get(DependentElement::REQUEST_PARENT_PARAMETER); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return DataIndexerInterface |
77
|
|
|
*/ |
78
|
|
|
protected function getParentDataIndexer() |
79
|
|
|
{ |
80
|
|
|
if ($this->parentElement instanceof DataIndexerElement) { |
81
|
|
|
return $this->parentElement->getDataIndexer(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return null; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|