|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace FSi\FixturesBundle\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
6
|
|
|
use FSi\Bundle\AdminBundle\Doctrine\Admin\CRUDElement; |
|
7
|
|
|
use FSi\Bundle\AdminBundle\Form\TypeSolver; |
|
8
|
|
|
use FSi\Component\DataGrid\DataGridFactoryInterface; |
|
9
|
|
|
use FSi\Component\DataSource\DataSourceFactoryInterface; |
|
10
|
|
|
use FSi\FixturesBundle\Form\TagType; |
|
11
|
|
|
use Symfony\Component\Form\FormFactoryInterface; |
|
12
|
|
|
|
|
13
|
|
|
class News extends CRUDElement |
|
14
|
|
|
{ |
|
15
|
|
|
public function getId() |
|
16
|
|
|
{ |
|
17
|
|
|
return 'news'; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function getClassName() |
|
21
|
|
|
{ |
|
22
|
|
|
return 'FSi\FixturesBundle\Entity\News'; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
protected function initDataGrid(DataGridFactoryInterface $factory) |
|
26
|
|
|
{ |
|
27
|
|
|
/* @var $datagrid \FSi\Component\DataGrid\DataGrid */ |
|
28
|
|
|
$datagrid = $factory->createDataGrid('news'); |
|
29
|
|
|
$datagrid->addColumn('title', 'text', array( |
|
30
|
|
|
'label' => 'admin.news.list.title', |
|
31
|
|
|
'field_mapping' => array('title', 'subtitle'), |
|
32
|
|
|
'value_glue' => '<br/>', |
|
33
|
|
|
'editable' => true |
|
34
|
|
|
)); |
|
35
|
|
|
$datagrid->addColumn('date', 'datetime', array( |
|
36
|
|
|
'label' => 'admin.news.list.date', |
|
37
|
|
|
'datetime_format' => 'Y-m-d', |
|
38
|
|
|
'editable' => true, |
|
39
|
|
|
'form_type' => array( |
|
40
|
|
|
'date' => TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\DateType', 'date') |
|
41
|
|
|
), |
|
42
|
|
|
'form_options' => array( |
|
43
|
|
|
'date' => array('widget' => 'single_text') |
|
44
|
|
|
) |
|
45
|
|
|
)); |
|
46
|
|
|
$datagrid->addColumn('created_at', 'datetime', array( |
|
47
|
|
|
'label' => 'admin.news.list.created_at' |
|
48
|
|
|
)); |
|
49
|
|
|
$datagrid->addColumn('visible', 'boolean', array( |
|
50
|
|
|
'label' => 'admin.news.list.visible' |
|
51
|
|
|
)); |
|
52
|
|
|
$datagrid->addColumn('creator_email', 'text', array( |
|
53
|
|
|
'label' => 'admin.news.list.creator_email' |
|
54
|
|
|
)); |
|
55
|
|
|
$datagrid->addColumn('photo', 'fsi_image', array( |
|
56
|
|
|
'label' => 'admin.news.list.photo', |
|
57
|
|
|
'width' => 100 |
|
58
|
|
|
)); |
|
59
|
|
|
$datagrid->addColumn('actions', 'action', array( |
|
60
|
|
|
'label' => 'admin.news.list.actions', |
|
61
|
|
|
'field_mapping' => array('id'), |
|
62
|
|
|
'actions' => array( |
|
63
|
|
|
'edit' => array( |
|
64
|
|
|
'route_name' => "fsi_admin_crud_edit", |
|
65
|
|
|
'additional_parameters' => array('element' => $this->getId()), |
|
66
|
|
|
'parameters_field_mapping' => array('id' => 'id') |
|
67
|
|
|
), |
|
68
|
|
|
'display' => array( |
|
69
|
|
|
'element' => DisplayNews::ID |
|
70
|
|
|
) |
|
71
|
|
|
) |
|
72
|
|
|
)); |
|
73
|
|
|
|
|
74
|
|
|
return $datagrid; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
protected function initDataSource(DataSourceFactoryInterface $factory) |
|
78
|
|
|
{ |
|
79
|
|
|
/* @var $datasource \FSi\Component\DataSource\DataSource */ |
|
80
|
|
|
$datasource = $factory->createDataSource('doctrine', array('entity' => $this->getClassName()), 'news'); |
|
81
|
|
|
$datasource->addField('title', 'text', 'like', array( |
|
82
|
|
|
'sortable' => false, |
|
83
|
|
|
'form_options' => array( |
|
84
|
|
|
'label' => 'admin.news.list.title', |
|
85
|
|
|
) |
|
86
|
|
|
)); |
|
87
|
|
|
$datasource->addField('created_at', 'date', 'between', array( |
|
88
|
|
|
'field' => 'createdAt', |
|
89
|
|
|
'sortable' => true, |
|
90
|
|
|
'form_from_options' => array( |
|
91
|
|
|
'widget' => 'single_text', |
|
92
|
|
|
'label' => 'admin.news.list.created_at_from', |
|
93
|
|
|
), |
|
94
|
|
|
'form_to_options' => array( |
|
95
|
|
|
'widget' => 'single_text', |
|
96
|
|
|
'label' => 'admin.news.list.created_at_to', |
|
97
|
|
|
) |
|
98
|
|
|
)); |
|
99
|
|
|
$datasource->addField('visible', 'boolean', 'eq', array( |
|
100
|
|
|
'sortable' => false, |
|
101
|
|
|
'form_options' => array( |
|
102
|
|
|
'label' => 'admin.news.list.visible', |
|
103
|
|
|
) |
|
104
|
|
|
)); |
|
105
|
|
|
$datasource->addField('creator_email', 'text', 'like', array( |
|
106
|
|
|
'field' => 'creatorEmail', |
|
107
|
|
|
'sortable' => true, |
|
108
|
|
|
'form_options' => array( |
|
109
|
|
|
'label' => 'admin.news.list.creator_email', |
|
110
|
|
|
) |
|
111
|
|
|
)); |
|
112
|
|
|
|
|
113
|
|
|
$datasource->setMaxResults(10); |
|
114
|
|
|
|
|
115
|
|
|
return $datasource; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
protected function initForm(FormFactoryInterface $factory, $data = null) |
|
119
|
|
|
{ |
|
120
|
|
|
$builder = $factory->createNamedBuilder( |
|
121
|
|
|
'news', |
|
122
|
|
|
TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\FormType', 'form'), |
|
|
|
|
|
|
123
|
|
|
$data, |
|
124
|
|
|
array( |
|
125
|
|
|
'data_class' => $this->getClassName() |
|
126
|
|
|
) |
|
127
|
|
|
); |
|
128
|
|
|
|
|
129
|
|
|
$builder->add( |
|
130
|
|
|
'title', |
|
131
|
|
|
TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\TextType', 'text'), |
|
|
|
|
|
|
132
|
|
|
array( |
|
133
|
|
|
'label' => 'admin.news.list.title', |
|
134
|
|
|
) |
|
135
|
|
|
); |
|
136
|
|
|
|
|
137
|
|
|
$builder->add( |
|
138
|
|
|
'date', |
|
139
|
|
|
TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\DateType', 'date'), |
|
|
|
|
|
|
140
|
|
|
array( |
|
141
|
|
|
'label' => 'admin.news.list.date', |
|
142
|
|
|
'widget' => 'single_text', |
|
143
|
|
|
'required' => false, |
|
144
|
|
|
) |
|
145
|
|
|
); |
|
146
|
|
|
|
|
147
|
|
|
$builder->add( |
|
148
|
|
|
'created_at', |
|
149
|
|
|
TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\DateType', 'date'), |
|
|
|
|
|
|
150
|
|
|
array( |
|
151
|
|
|
'label' => 'admin.news.list.created_at', |
|
152
|
|
|
'widget' => 'single_text' |
|
153
|
|
|
) |
|
154
|
|
|
); |
|
155
|
|
|
|
|
156
|
|
|
$builder->add( |
|
157
|
|
|
'visible', |
|
158
|
|
|
TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\CheckboxType', 'checkbox'), |
|
|
|
|
|
|
159
|
|
|
array( |
|
160
|
|
|
'label' => 'admin.news.list.visible', |
|
161
|
|
|
'required' => false, |
|
162
|
|
|
) |
|
163
|
|
|
); |
|
164
|
|
|
|
|
165
|
|
|
$builder->add( |
|
166
|
|
|
'creator_email', |
|
167
|
|
|
TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\EmailType', 'email'), |
|
|
|
|
|
|
168
|
|
|
array( |
|
169
|
|
|
'label' => 'admin.news.list.creator_email' |
|
170
|
|
|
) |
|
171
|
|
|
); |
|
172
|
|
|
|
|
173
|
|
|
$builder->add( |
|
174
|
|
|
'photo', |
|
175
|
|
|
TypeSolver::getFormType('FSi\Bundle\DoctrineExtensionsBundle\Form\Type\FSi\ImageType', 'fsi_image'), |
|
|
|
|
|
|
176
|
|
|
array( |
|
177
|
|
|
'label' => 'admin.news.list.photo' |
|
178
|
|
|
) |
|
179
|
|
|
); |
|
180
|
|
|
|
|
181
|
|
|
$builder->add( |
|
182
|
|
|
'tags', |
|
183
|
|
|
TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\CollectionType', 'collection'), |
|
|
|
|
|
|
184
|
|
|
array( |
|
185
|
|
|
TypeSolver::hasCollectionEntryTypeOption() ? 'entry_type' : 'type' => |
|
186
|
|
|
TypeSolver::getFormType('FSi\FixturesBundle\Form\TagType', new TagType()), |
|
187
|
|
|
'label' => 'admin.news.list.tags', |
|
188
|
|
|
'allow_add' => true, |
|
189
|
|
|
'allow_delete' => true, |
|
190
|
|
|
'by_reference' => false, |
|
191
|
|
|
) |
|
192
|
|
|
); |
|
193
|
|
|
|
|
194
|
|
|
$builder->add( |
|
195
|
|
|
'nonEditableTags', |
|
196
|
|
|
TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\CollectionType', 'collection'), |
|
|
|
|
|
|
197
|
|
|
array( |
|
198
|
|
|
TypeSolver::hasCollectionEntryTypeOption() ? 'entry_type' : 'type' => |
|
199
|
|
|
TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\TextType', 'text'), |
|
200
|
|
|
'data' => new ArrayCollection(['Tag 1', 'Tag 2', 'Tag 3']), |
|
201
|
|
|
'label' => 'admin.news.list.non_editable_tags', |
|
202
|
|
|
'allow_add' => false, |
|
203
|
|
|
'allow_delete' => false, |
|
204
|
|
|
'mapped' => false, |
|
205
|
|
|
'required' => false |
|
206
|
|
|
) |
|
207
|
|
|
); |
|
208
|
|
|
|
|
209
|
|
|
return $builder->getForm(); |
|
210
|
|
|
} |
|
211
|
|
|
} |
|
212
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.