1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DoS\SettingsBundle\Schema; |
4
|
|
|
|
5
|
|
|
use Sylius\Bundle\SettingsBundle\Schema\SettingsBuilderInterface; |
6
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
7
|
|
|
use Symfony\Component\Validator\Constraints\Locale; |
8
|
|
|
use Symfony\Component\Validator\Constraints\NotBlank; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* General settings schema. |
12
|
|
|
*/ |
13
|
|
|
class GeneralSettingsSchema implements SchemaInterface |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var array |
17
|
|
|
*/ |
18
|
|
|
protected $defaults; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @param array $defaults |
22
|
|
|
*/ |
23
|
|
|
public function __construct(array $defaults = array()) |
24
|
|
|
{ |
25
|
|
|
$this->defaults = $defaults; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
|
|
public function buildSettings(SettingsBuilderInterface $builder) |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
$builder |
34
|
|
|
->setDefaults(array_merge(array( |
35
|
|
|
'domain' => $_SERVER['HTTP_HOST'], |
36
|
|
|
'title' => 'DoS - Modern dos for everyone', |
37
|
|
|
'meta_keywords' => 'DoS', |
38
|
|
|
'meta_description' => 'DoS is modern for everyone', |
39
|
|
|
'meta_robots' => 'index, follow', |
40
|
|
|
'locale' => 'th', |
41
|
|
|
'currency' => 'THB', |
42
|
|
|
), $this->defaults)) |
43
|
|
|
->setAllowedTypes(array( |
44
|
|
|
'domain' => array('string'), |
45
|
|
|
'title' => array('string'), |
46
|
|
|
'meta_keywords' => array('string'), |
47
|
|
|
'meta_description' => array('string'), |
48
|
|
|
'meta_robots' => array('string'), |
49
|
|
|
'locale' => array('string'), |
50
|
|
|
'currency' => array('string'), |
51
|
|
|
)) |
52
|
|
|
; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritdoc} |
57
|
|
|
*/ |
58
|
|
|
public function buildForm(FormBuilderInterface $builder) |
59
|
|
|
{ |
60
|
|
|
$builder |
61
|
|
|
->add('domain', 'text', array( |
62
|
|
|
'label' => 'ui.trans.settings.general.form.domain', |
63
|
|
|
'constraints' => array( |
64
|
|
|
new NotBlank(), |
65
|
|
|
), |
66
|
|
|
)) |
67
|
|
|
->add('title', 'text', array( |
68
|
|
|
'label' => 'ui.trans.settings.general.form.title', |
69
|
|
|
'constraints' => array( |
70
|
|
|
new NotBlank(), |
71
|
|
|
), |
72
|
|
|
)) |
73
|
|
|
->add('meta_keywords', 'text', array( |
74
|
|
|
'label' => 'ui.trans.settings.general.form.meta_keywords', |
75
|
|
|
'constraints' => array( |
76
|
|
|
new NotBlank(), |
77
|
|
|
), |
78
|
|
|
)) |
79
|
|
|
->add('meta_description', 'textarea', array( |
80
|
|
|
'label' => 'ui.trans.settings.general.form.meta_description', |
81
|
|
|
'constraints' => array( |
82
|
|
|
new NotBlank(), |
83
|
|
|
), |
84
|
|
|
)) |
85
|
|
|
->add('meta_robots', 'text', array( |
86
|
|
|
'label' => 'ui.trans.settings.general.form.meta_robots', |
87
|
|
|
'constraints' => array( |
88
|
|
|
new NotBlank(), |
89
|
|
|
), |
90
|
|
|
)) |
91
|
|
|
->add('locale', 'locale', array( |
92
|
|
|
'label' => 'ui.trans.settings.general.form.locale', |
93
|
|
|
'constraints' => array( |
94
|
|
|
new NotBlank(), |
95
|
|
|
new Locale(), |
96
|
|
|
), |
97
|
|
|
)) |
98
|
|
|
; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: