1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Odiseo\BlogBundle\Form\Type; |
4
|
|
|
|
5
|
|
|
use Odiseo\BlogBundle\Model\ArticleCategory; |
6
|
|
|
use Sylius\Bundle\ResourceBundle\Form\EventSubscriber\AddCodeFormSubscriber; |
7
|
|
|
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; |
8
|
|
|
use Sylius\Bundle\ResourceBundle\Form\Type\ResourceTranslationsType; |
9
|
|
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType; |
10
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; |
11
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CollectionType; |
12
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @author Diego D'amico <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
final class ArticleType extends AbstractResourceType |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* {@inheritdoc} |
21
|
|
|
*/ |
22
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options) |
23
|
|
|
{ |
24
|
|
|
$builder |
25
|
|
|
->addEventSubscriber(new AddCodeFormSubscriber(null, [ |
26
|
|
|
'label' => 'odiseo_blog.form.article.code', |
27
|
|
|
])) |
28
|
|
|
->add('enabled', CheckboxType::class, [ |
29
|
|
|
'label' => 'odiseo_blog.form.article.enabled', |
30
|
|
|
'required' => true, |
31
|
|
|
]) |
32
|
|
|
->add('translations', ResourceTranslationsType::class, [ |
33
|
|
|
'entry_type' => ArticleTranslationType::class, |
34
|
|
|
'label' => 'odiseo_blog.form.article.translations', |
35
|
|
|
]) |
36
|
|
|
->add('categories', EntityType::class, [ |
37
|
|
|
'class' => ArticleCategory::class, |
38
|
|
|
'multiple' => true, |
39
|
|
|
'expanded' => true, |
40
|
|
|
'label' => 'odiseo_blog.form.article.categories', |
41
|
|
|
'required' => false, |
42
|
|
|
]) |
43
|
|
|
->add('images', CollectionType::class, [ |
44
|
|
|
'entry_type' => ArticleImageType::class, |
45
|
|
|
'allow_add' => true, |
46
|
|
|
'allow_delete' => true, |
47
|
|
|
'by_reference' => false, |
48
|
|
|
'label' => 'odiseo_blog.form.article.images', |
49
|
|
|
'block_name' => 'entry', |
50
|
|
|
'required' => false, |
51
|
|
|
]) |
52
|
|
|
; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritdoc} |
57
|
|
|
*/ |
58
|
|
|
public function getBlockPrefix() |
59
|
|
|
{ |
60
|
|
|
return 'odiseo_blog_article'; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|