deblan.tv/src/Deblan/Bundle/BlogBundle/Form/Type/PostType.php

163 lines
4.6 KiB
PHP
Raw Normal View History

2015-03-02 21:57:49 +01:00
<?php
namespace Deblan\Bundle\BlogBundle\Form\Type;
use Propel\PropelBundle\Form\BaseAbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\DateTime;
use Symfony\Component\Validator\Constraints\NotBlank;
use Trinity\Component\Form\EventListener\FileDeleteFormListener;
use Trinity\Component\Form\DataTransformer\StringToFileTransformer;
use Symfony\Component\Validator\Constraints\Image;
class PostType extends BaseAbstractType
{
protected $options = array(
'data_class' => 'Deblan\Bundle\BlogBundle\Model\Post',
'name' => 'post',
);
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add(
'Title',
'text',
array(
'label' => 'Titre',
'constraints' => array(
new NotBlank(),
),
)
);
$builder->add(
'Content',
'textarea',
array(
'label' => 'Article',
'attr' => array(
'class' => 'markitup',
'data-set' => $builder->getData()->getContentFormat(),
),
'constraints' => array(
new NotBlank(),
),
)
);
// $builder->add(
// 'Content',
// 'ace_editor',
// array(
// 'label' => 'Article',
// 'wrapper_attr' => array(),
// 'width' => '100%',
// 'height' => 500,
// 'font_size' => 12,
// 'mode' => 'ace/mode/'.$builder->getData()->getContentFormat(),
// 'theme' => 'ace/theme/idle_fingers',
// 'tab_size' => 4,
// 'read_only' => false,
// 'use_soft_tabs' => false,
// 'use_wrap_mode' => true,
// 'show_print_margin' => false,
// 'highlight_active_line' => true,
// 'constraints' => array(
// new NotBlank(),
// ),
// )
// );
$builder->add(
'ContentFormat',
'choice',
array(
'label' => 'Format',
'required' => true,
'choices' => array(
'html' => 'HTML',
'markdown' => 'Markdown',
),
'constraints' => array(
new NotBlank(),
),
)
);
$builder->add(
'Tags',
'text',
array(
'constraints' => array(
//new NotBlank(),
),
)
);
$builder->add(
$builder->create(
'Picture',
'file',
array(
'label' => 'Illustration',
'constraints' => array(
new Image(),
),
)
)->addModelTransformer(new StringToFileTransformer($builder->getData(), 'Picture'))
);
$builder->addEventSubscriber(
new FileDeleteFormListener(
$builder->getFormFactory(),
array(
'Picture',
)
)
);
$builder->add(
'PublishedAt',
'date',
array(
'label' => 'Date de publication',
'widget' => 'single_text',
'format' => 'yyyy-MM-dd HH:mm:ss',
'attr' => array(
'class' => 'datetimepicker',
),
'constraints' => array(
new DateTime(),
),
)
);
$builder->add(
'Categories',
'model',
array(
'label' => 'Catégories',
'class' => 'Deblan\Bundle\BlogBundle\Model\Category',
'query' => \Deblan\Bundle\BlogBundle\Model\CategoryQuery::create()->filterByActive(true)->orderByTitle(),
'multiple' => true,
'expanded' => false,
'attr' => array(
'class' => 'chosen-select',
'data-placeholder' => 'Sélectionnez un groupe'
),
)
);
$builder->add(
'Active',
'checkbox',
array(
'label' => 'En ligne',
)
);
}
}