1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Silverback\ApiComponentBundle\Factory\Entity\Content\Component; |
4
|
|
|
|
5
|
|
|
use Silverback\ApiComponentBundle\Entity\Content\Component\AbstractComponent; |
6
|
|
|
use Silverback\ApiComponentBundle\Entity\Content\Component\ComponentLocation; |
7
|
|
|
use Silverback\ApiComponentBundle\Factory\Entity\AbstractFactory; |
8
|
|
|
|
9
|
|
|
abstract class AbstractComponentFactory extends AbstractFactory |
10
|
|
|
{ |
11
|
|
|
public const COMPONENT_OPS = [ |
12
|
|
|
'className' => null, |
13
|
|
|
'parentComponent' => null, |
14
|
|
|
'parentContent' => null, |
15
|
|
|
'componentGroup' => null, |
16
|
|
|
'dynamicPageClass' => null |
17
|
|
|
]; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param AbstractComponent $component |
21
|
|
|
* @param array|null $ops |
22
|
|
|
*/ |
23
|
22 |
|
protected function init($component, ?array $ops = null): void |
24
|
|
|
{ |
25
|
22 |
|
parent::init($component, $ops); |
26
|
|
|
if ( |
27
|
22 |
|
$this->ops['parentContent'] && |
28
|
22 |
|
!$component->hasParentContent($this->ops['parentContent']) |
29
|
|
|
) { |
30
|
|
|
$location = new ComponentLocation($this->ops['parentContent'], $component); |
31
|
|
|
$component->addLocation($location); |
32
|
|
|
$this->manager->persist($location); |
33
|
|
|
} |
34
|
|
|
if ( |
35
|
22 |
|
$this->ops['dynamicPageClass'] |
36
|
|
|
) { |
37
|
|
|
$location = new ComponentLocation(null, $component); |
38
|
|
|
$location->setDynamicPageClass($this->ops['dynamicPageClass']); |
39
|
|
|
$component->addLocation($location); |
40
|
|
|
$this->manager->persist($location); |
41
|
|
|
} |
42
|
22 |
|
} |
43
|
|
|
|
44
|
18 |
|
protected static function getIgnoreOps(): array |
45
|
|
|
{ |
46
|
|
|
return [ |
47
|
18 |
|
'parentContent', |
48
|
|
|
'dynamicPageClass' |
49
|
|
|
]; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @inheritdoc |
54
|
|
|
*/ |
55
|
43 |
|
protected static function defaultOps(): array |
56
|
|
|
{ |
57
|
43 |
|
return self::COMPONENT_OPS; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|