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\Admin; |
26
|
|
|
|
27
|
|
|
use Symfony\Component\Form\AbstractType; |
28
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
29
|
|
|
use Symfony\Component\Form\FormError; |
30
|
|
|
use Symfony\Component\Form\FormEvents; |
31
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolverInterface; |
32
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
33
|
|
|
|
34
|
|
|
class MainEditType extends AbstractType |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
public $app; |
37
|
|
|
|
38
|
663 |
|
public function __construct(\Silex\Application $app) |
|
|
|
|
39
|
|
|
{ |
40
|
663 |
|
$this->app = $app; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritdoc} |
45
|
|
|
*/ |
46
|
4 |
|
public function buildForm(FormBuilderInterface $builder, array $options) |
47
|
|
|
{ |
48
|
4 |
|
$app = $this->app; |
49
|
|
|
|
50
|
|
|
$builder |
51
|
4 |
|
->add('name', 'text', array( |
|
|
|
|
52
|
4 |
|
'label' => '名称', |
53
|
|
|
'required' => true, |
54
|
|
|
'constraints' => array( |
|
|
|
|
55
|
4 |
|
new Assert\NotBlank(), |
56
|
4 |
|
new Assert\Length(array( |
57
|
4 |
|
'max' => $app['config']['stext_len'], |
58
|
|
|
)) |
59
|
|
|
) |
60
|
|
|
)) |
61
|
4 |
|
->add('url', 'text', array( |
|
|
|
|
62
|
4 |
|
'label' => 'URL', |
63
|
|
|
'required' => true, |
64
|
|
|
'constraints' => array( |
65
|
4 |
|
new Assert\NotBlank(), |
66
|
4 |
|
new Assert\Length(array( |
67
|
4 |
|
'max' => $app['config']['stext_len'], |
68
|
|
|
)), |
69
|
4 |
|
new Assert\Regex(array( |
70
|
4 |
|
'pattern' => '/^([0-9a-zA-Z_\-]+\/?)+(?<!\/)$/', |
71
|
|
|
)), |
72
|
|
|
) |
73
|
|
|
)) |
74
|
4 |
|
->add('file_name', 'text', array( |
|
|
|
|
75
|
4 |
|
'label' => 'ファイル名', |
76
|
|
|
'required' => true, |
77
|
|
|
'constraints' => array( |
78
|
4 |
|
new Assert\NotBlank(), |
79
|
4 |
|
new Assert\Length(array( |
80
|
4 |
|
'max' => $app['config']['stext_len'], |
81
|
|
|
)), |
82
|
4 |
|
new Assert\Regex(array( |
83
|
4 |
|
'pattern' => '/^([0-9a-zA-Z_\-]+\/?)+$/', |
84
|
|
|
)), |
85
|
|
|
) |
86
|
|
|
)) |
87
|
4 |
|
->add('tpl_data', 'textarea', array( |
|
|
|
|
88
|
4 |
|
'label' => false, |
89
|
|
|
'mapped' => false, |
90
|
|
|
'required' => true, |
91
|
|
|
'constraints' => array() |
92
|
|
|
)) |
93
|
4 |
|
->add('author', 'text', array( |
|
|
|
|
94
|
4 |
|
'label' => 'author', |
95
|
|
|
'required' => false, |
96
|
|
|
'constraints' => array( |
|
|
|
|
97
|
4 |
|
new Assert\Length(array( |
98
|
4 |
|
'max' => $app['config']['stext_len'], |
99
|
|
|
)) |
100
|
|
|
) |
101
|
|
|
)) |
102
|
4 |
|
->add('description', 'text', array( |
|
|
|
|
103
|
4 |
|
'label' => 'description', |
104
|
|
|
'required' => false, |
105
|
|
|
'constraints' => array( |
|
|
|
|
106
|
4 |
|
new Assert\Length(array( |
107
|
4 |
|
'max' => $app['config']['stext_len'], |
108
|
|
|
)) |
109
|
|
|
) |
110
|
|
|
)) |
111
|
4 |
|
->add('keyword', 'text', array( |
|
|
|
|
112
|
4 |
|
'label' => 'keyword', |
113
|
|
|
'required' => false, |
114
|
|
|
'constraints' => array( |
|
|
|
|
115
|
4 |
|
new Assert\Length(array( |
116
|
4 |
|
'max' => $app['config']['stext_len'], |
117
|
|
|
)) |
118
|
|
|
) |
119
|
|
|
)) |
120
|
4 |
|
->add('meta_robots', 'text', array( |
|
|
|
|
121
|
4 |
|
'label' => 'robots', |
122
|
|
|
'required' => false, |
123
|
|
|
'constraints' => array( |
|
|
|
|
124
|
4 |
|
new Assert\Length(array( |
125
|
4 |
|
'max' => $app['config']['stext_len'], |
126
|
|
|
)) |
127
|
|
|
) |
128
|
|
|
)) |
129
|
4 |
|
->add('DeviceType', 'entity', array( |
130
|
4 |
|
'class' => 'Eccube\Entity\Master\DeviceType', |
131
|
|
|
'property' => 'id', |
132
|
|
|
)) |
133
|
4 |
|
->add('id', 'hidden') |
134
|
4 |
View Code Duplication |
->addEventListener(FormEvents::POST_SUBMIT, function($event) use ($app) { |
|
|
|
|
135
|
2 |
|
$form = $event->getForm(); |
136
|
2 |
|
$url = $form['url']->getData(); |
137
|
2 |
|
$DeviceType = $form['DeviceType']->getData(); |
138
|
2 |
|
$page_id = $form['id']->getData(); |
139
|
|
|
|
140
|
2 |
|
$qb = $app['orm.em']->createQueryBuilder(); |
141
|
2 |
|
$qb->select('p') |
142
|
2 |
|
->from('Eccube\\Entity\\PageLayout', 'p') |
143
|
2 |
|
->where('p.url = :url') |
144
|
2 |
|
->setParameter('url', $url) |
145
|
2 |
|
->andWhere('p.DeviceType = :DeviceType') |
146
|
2 |
|
->setParameter('DeviceType', $DeviceType) |
147
|
|
|
; |
148
|
2 |
|
if (is_null($page_id)) { |
149
|
|
|
$qb |
150
|
1 |
|
->andWhere('p.id IS NOT NULL'); |
151
|
|
|
} else { |
152
|
|
|
$qb |
153
|
1 |
|
->andWhere('p.id <> :page_id') |
154
|
1 |
|
->setParameter('page_id', $page_id); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
$PageLayout = $qb |
158
|
2 |
|
->getQuery() |
159
|
2 |
|
->getResult(); |
160
|
2 |
|
if (count($PageLayout) > 0) { |
161
|
|
|
$form['url']->addError(new FormError('※ 同じURLのデータが存在しています。別のURLを入力してください。')); |
162
|
|
|
} |
163
|
4 |
|
}); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* {@inheritdoc} |
168
|
|
|
*/ |
169
|
4 |
|
public function setDefaultOptions(OptionsResolverInterface $resolver) |
170
|
|
|
{ |
171
|
4 |
|
$resolver->setDefaults(array( |
172
|
4 |
|
'data_class' => 'Eccube\Entity\PageLayout', |
173
|
|
|
)); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* {@inheritdoc} |
178
|
|
|
*/ |
179
|
663 |
|
public function getName() |
180
|
|
|
{ |
181
|
663 |
|
return 'main_edit'; |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|