1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file contains a form creator for News articles |
4
|
|
|
* |
5
|
|
|
* @license https://github.com/allejo/bzion/blob/master/LICENSE.md GNU General Public License Version 3 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace BZIon\Form\Creator; |
9
|
|
|
|
10
|
|
|
use BZIon\Form\Type\ModelType; |
11
|
|
|
use Symfony\Component\Validator\Constraints\Length; |
12
|
|
|
use Symfony\Component\Validator\Constraints\NotBlank; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Form creator for news |
16
|
|
|
*/ |
17
|
|
|
class NewsFormCreator extends ModelFormCreator |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* {@inheritdoc} |
21
|
|
|
*/ |
22
|
|
|
protected function build($builder) |
23
|
|
|
{ |
24
|
|
|
return $builder |
25
|
|
|
->add('category', new ModelType('NewsCategory'), array( |
26
|
|
|
'constraints' => new NotBlank() |
27
|
|
|
)) |
28
|
|
|
->add('subject', 'text', array( |
29
|
|
|
'constraints' => array( |
30
|
|
|
new NotBlank(), new Length(array( |
31
|
|
|
'max' => 100, |
32
|
|
|
)), |
33
|
|
|
), |
34
|
|
|
)) |
35
|
|
|
->add('content', 'textarea', array( |
36
|
|
|
'constraints' => new NotBlank() |
37
|
|
|
)) |
38
|
|
|
->add('status', 'choice', array( |
39
|
|
|
'choices' => array( |
40
|
|
|
'published' => 'Public', |
41
|
|
|
'revision' => 'Revision', |
42
|
|
|
'draft' => 'Draft', |
43
|
|
|
), |
44
|
|
|
)) |
45
|
|
|
->add('enter', 'submit', [ |
46
|
|
|
'attr' => [ |
47
|
|
|
'class' => 'c-button--blue pattern pattern--downward-stripes', |
48
|
|
|
], |
49
|
|
|
]); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
* |
55
|
|
|
* @param \News $article |
56
|
|
|
*/ |
57
|
|
|
public function fill($form, $article) |
58
|
|
|
{ |
59
|
|
|
$form->get('category')->setData($article->getCategory()); |
60
|
|
|
$form->get('subject')->setData($article->getSubject()); |
61
|
|
|
$form->get('content')->setData($article->getContent()); |
62
|
|
|
$form->get('status')->setData($article->getStatus()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* {@inheritdoc} |
67
|
|
|
* |
68
|
|
|
* @param \News $article |
69
|
|
|
*/ |
70
|
|
|
public function update($form, $article) |
71
|
|
|
{ |
72
|
|
|
$article->updateCategory($form->get('category')->getData()->getId()) |
73
|
|
|
->updateSubject($form->get('subject')->getData()) |
74
|
|
|
->updateContent($form->get('content')->getData()) |
75
|
|
|
->updateStatus($form->get('status')->getData()) |
76
|
|
|
->updateLastEditor($this->me->getId()) |
77
|
|
|
->updateEditTimestamp(); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* {@inheritdoc} |
82
|
|
|
*/ |
83
|
|
|
public function enter($form) |
84
|
|
|
{ |
85
|
|
|
return \News::addNews( |
86
|
|
|
$form->get('subject')->getData(), |
87
|
|
|
$form->get('content')->getData(), |
88
|
|
|
$this->me->getId(), |
89
|
|
|
$form->get('category')->getData()->getId(), |
90
|
|
|
$form->get('status')->getData() |
91
|
|
|
); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|