1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of EC-CUBE |
4
|
|
|
* |
5
|
|
|
* Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. |
6
|
|
|
* |
7
|
|
|
* http://www.lockon.co.jp/ |
8
|
|
|
* |
9
|
|
|
* This program is free software; you can redistribute it and/or |
10
|
|
|
* modify it under the terms of the GNU General Public License |
11
|
|
|
* as published by the Free Software Foundation; either version 2 |
12
|
|
|
* of the License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU General Public License |
20
|
|
|
* along with this program; if not, write to the Free Software |
21
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
namespace Eccube\Form\Type; |
26
|
|
|
|
27
|
|
|
use Symfony\Component\Form\AbstractType; |
28
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
29
|
|
|
use Symfony\Component\Form\FormInterface; |
30
|
|
|
use Symfony\Component\Form\FormView; |
31
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolverInterface; |
32
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
33
|
|
|
|
34
|
|
|
class NameType extends AbstractType |
35
|
|
|
{ |
36
|
681 |
|
public function __construct($config = array('name_len' => 50)) |
37
|
|
|
{ |
38
|
681 |
|
$this->config = $config; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
193 |
|
public function buildForm(FormBuilderInterface $builder, array $options) |
45
|
|
|
{ |
46
|
193 |
|
$options['lastname_options']['required'] = $options['required']; |
47
|
193 |
|
$options['firstname_options']['required'] = $options['required']; |
48
|
|
|
|
49
|
|
|
// required の場合は NotBlank も追加する |
50
|
193 |
|
if ($options['required']) { |
51
|
165 |
|
$options['lastname_options']['constraints'] = array_merge(array( |
52
|
165 |
|
new Assert\NotBlank(array()), |
53
|
165 |
|
), $options['lastname_options']['constraints']); |
54
|
|
|
|
55
|
165 |
|
$options['firstname_options']['constraints'] = array_merge(array( |
56
|
165 |
|
new Assert\NotBlank(array()), |
57
|
165 |
|
), $options['firstname_options']['constraints']); |
58
|
|
|
} |
59
|
|
|
|
60
|
193 |
View Code Duplication |
if (!isset($options['options']['error_bubbling'])) { |
61
|
193 |
|
$options['options']['error_bubbling'] = $options['error_bubbling']; |
62
|
|
|
} |
63
|
|
|
|
64
|
193 |
|
if (empty($options['lastname_name'])) { |
65
|
193 |
|
$options['lastname_name'] = $builder->getName() . '01'; |
66
|
|
|
} |
67
|
193 |
|
if (empty($options['firstname_name'])) { |
68
|
193 |
|
$options['firstname_name'] = $builder->getName() . '02'; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$builder |
72
|
193 |
|
->add($options['lastname_name'], 'text', array_merge_recursive($options['options'], $options['lastname_options'])) |
73
|
193 |
|
->add($options['firstname_name'], 'text', array_merge_recursive($options['options'], $options['firstname_options'])) |
74
|
|
|
; |
75
|
|
|
|
76
|
193 |
|
$builder->setAttribute('lastname_name', $options['lastname_name']); |
77
|
193 |
|
$builder->setAttribute('firstname_name', $options['firstname_name']); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* {@inheritdoc} |
82
|
|
|
*/ |
83
|
34 |
|
public function buildView(FormView $view, FormInterface $form, array $options) |
84
|
|
|
{ |
85
|
34 |
|
$builder = $form->getConfig(); |
86
|
34 |
|
$view->vars['lastname_name'] = $builder->getAttribute('lastname_name'); |
87
|
34 |
|
$view->vars['firstname_name'] = $builder->getAttribute('firstname_name'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* {@inheritdoc} |
92
|
|
|
*/ |
93
|
193 |
|
public function setDefaultOptions(OptionsResolverInterface $resolver) |
94
|
|
|
{ |
95
|
193 |
|
$resolver->setDefaults(array( |
96
|
193 |
|
'options' => array(), |
97
|
|
|
'lastname_options' => array( |
98
|
|
|
'attr' => array( |
99
|
|
|
'placeholder' => 'Name01', |
100
|
|
|
), |
101
|
|
|
'constraints' => array( |
102
|
193 |
|
new Assert\Length(array( |
103
|
193 |
|
'max' => $this->config['name_len'], |
104
|
|
|
)), |
105
|
193 |
|
new Assert\Regex(array( |
|
|
|
|
106
|
193 |
|
'pattern' => '/^[^\s ]+$/u', |
107
|
|
|
'message' => 'form.type.name.firstname.nothasspace' |
108
|
|
|
)) |
109
|
|
|
), |
110
|
|
|
), |
111
|
|
|
'firstname_options' => array( |
112
|
|
|
'attr' => array( |
113
|
|
|
'placeholder' => 'Name02', |
114
|
|
|
), |
115
|
|
|
'constraints' => array( |
116
|
193 |
|
new Assert\Length(array( |
117
|
193 |
|
'max' => $this->config['name_len'], |
118
|
|
|
)), |
119
|
193 |
|
new Assert\Regex(array( |
|
|
|
|
120
|
193 |
|
'pattern' => '/^[^\s ]+$/u', |
121
|
|
|
'message' => 'form.type.name.lastname.nothasspace' |
122
|
|
|
)) |
123
|
|
|
), |
124
|
|
|
), |
125
|
193 |
|
'lastname_name' => '', |
126
|
193 |
|
'firstname_name' => '', |
127
|
|
|
'error_bubbling' => false, |
128
|
|
|
'inherit_data' => true, |
129
|
|
|
'trim' => true, |
130
|
|
|
)); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* {@inheritdoc} |
135
|
|
|
*/ |
136
|
681 |
|
public function getName() |
137
|
|
|
{ |
138
|
681 |
|
return 'name'; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|