1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file was created by developers working at BitBag |
5
|
|
|
* Do you need more information about us and what we do? Visit our https://bitbag.io website! |
6
|
|
|
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
declare(strict_types=1); |
10
|
|
|
|
11
|
|
|
namespace BitBag\SyliusCmsPlugin\Fixture; |
12
|
|
|
|
13
|
|
|
use BitBag\SyliusCmsPlugin\Fixture\Factory\FixtureFactoryInterface; |
14
|
|
|
use Sylius\Bundle\FixturesBundle\Fixture\AbstractFixture; |
15
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
16
|
|
|
use Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition; |
17
|
|
|
use Symfony\Component\Config\Definition\Builder\IntegerNodeDefinition; |
18
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
19
|
|
|
use Symfony\Component\Config\Definition\Builder\ScalarNodeDefinition; |
20
|
|
|
|
21
|
|
|
final class BlockFixture extends AbstractFixture |
22
|
|
|
{ |
23
|
|
|
/** @var FixtureFactoryInterface */ |
24
|
|
|
private $blockFixtureFactory; |
25
|
|
|
|
26
|
|
|
public function __construct(FixtureFactoryInterface $blockFixtureFactory) |
27
|
|
|
{ |
28
|
|
|
$this->blockFixtureFactory = $blockFixtureFactory; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function load(array $options): void |
32
|
|
|
{ |
33
|
|
|
$this->blockFixtureFactory->load($options['custom']); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function getName(): string |
37
|
|
|
{ |
38
|
|
|
return 'block'; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void |
42
|
|
|
{ |
43
|
|
|
$optionsNode |
44
|
|
|
->children() |
45
|
|
|
->arrayNode('custom') |
46
|
|
|
->arrayPrototype() |
47
|
|
|
->children() |
48
|
|
|
->booleanNode('remove_existing')->defaultTrue()->end() |
49
|
|
|
->integerNode('number')->defaultNull()->end() |
|
|
|
|
50
|
|
|
->booleanNode('last_four_products')->defaultFalse()->end() |
51
|
|
|
->booleanNode('enabled')->defaultTrue()->end() |
52
|
|
|
->integerNode('products')->defaultNull()->end() |
53
|
|
|
->append($this->createArrayOfScalars('productCodes')) |
54
|
|
|
->append($this->createArrayOfScalars('taxons')) |
55
|
|
|
->append($this->createArrayOfScalars('sections')) |
56
|
|
|
->append($this->createArrayOfScalars('channels')) |
57
|
|
|
->append($this->translationsConfiguration()) |
58
|
|
|
->end() |
59
|
|
|
->end() |
60
|
|
|
->end() |
61
|
|
|
->end() |
62
|
|
|
; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
private function createArrayOfScalars(string $name): NodeDefinition |
66
|
|
|
{ |
67
|
|
|
$nodeDefinition = new ScalarNodeDefinition($name); |
68
|
|
|
$nodeDefinition->defaultNull()->end(); |
69
|
|
|
return $nodeDefinition; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
private function translationsConfiguration(): NodeDefinition |
73
|
|
|
{ |
74
|
|
|
$translationsNodeDefinition = new ArrayNodeDefinition('translations'); |
75
|
|
|
$translationsNodeDefinition |
76
|
|
|
->arrayPrototype() |
77
|
|
|
->children() |
78
|
|
|
->scalarNode('name')->end() |
79
|
|
|
->scalarNode('content')->end() |
|
|
|
|
80
|
|
|
->scalarNode('link')->end() |
81
|
|
|
->scalarNode('image_path')->end() |
82
|
|
|
->end() |
83
|
|
|
->end() |
84
|
|
|
; |
85
|
|
|
|
86
|
|
|
return $translationsNodeDefinition; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|