gist/src/Gist/Form/CreateGistForm.php

117 lines
2.7 KiB
PHP
Raw Normal View History

2015-05-05 22:04:04 +02:00
<?php
namespace Gist\Form;
use Symfony\Component\Validator\Constraints\NotBlank;
/**
2016-11-13 00:44:23 +01:00
* Class CreateGistForm.
*
2015-05-05 22:04:04 +02:00
* @author Simon Vieille <simon@deblan.fr>
*/
class CreateGistForm extends AbstractForm
{
2016-11-13 00:44:23 +01:00
/**
* {@inheritdoc}
*/
2015-05-05 22:04:04 +02:00
public function build(array $options = array())
{
$this->builder->add(
'title',
'text',
array(
'required' => false,
'attr' => array(
'class' => 'form-control',
'placeholder' => $this->translator->trans('form.title.placeholder'),
),
)
);
$this->builder->add(
'content',
'textarea',
array(
2017-06-19 20:36:51 +02:00
'required' => false,
2015-05-05 22:04:04 +02:00
'attr' => array(
'class' => 'form-control',
'rows' => 10,
),
2015-11-10 21:49:42 +01:00
'trim' => false,
2015-05-05 22:04:04 +02:00
'constraints' => array(
2017-06-19 20:36:51 +02:00
),
)
);
$this->builder->add(
'file',
'file',
array(
'required' => false,
'attr' => array(
),
'constraints' => array(
2015-05-05 22:04:04 +02:00
),
)
);
$this->builder->add(
'type',
'choice',
array(
'required' => true,
'choices' => $this->getTypes(),
'constraints' => array(
new NotBlank(),
),
)
);
$this->builder->add(
'cipher',
'choice',
array(
'required' => true,
'choices' => array(
2015-05-05 23:24:37 +02:00
'no' => $this->translator->trans('form.cipher.choice.no'),
'yes' => $this->translator->trans('form.cipher.choice.yes'),
2015-05-05 22:04:04 +02:00
),
)
);
2015-05-09 01:03:51 +02:00
return $this->builder;
2015-05-05 22:04:04 +02:00
}
2016-11-13 00:44:23 +01:00
/**
* Returns the types for generating the form.
*
* @return array
*/
2015-05-05 22:04:04 +02:00
protected function getTypes()
{
$types = array(
2015-05-09 12:30:33 +02:00
'html' => '',
2015-05-05 22:04:04 +02:00
'css' => '',
2015-05-06 22:24:42 +02:00
'javascript' => '',
2015-05-05 22:04:04 +02:00
'php' => '',
'sql' => '',
2015-05-09 12:30:33 +02:00
'xml' => '',
2016-11-13 00:44:23 +01:00
'yaml' => '',
2018-09-20 10:31:32 +02:00
'markdown' => '',
2015-05-05 22:04:04 +02:00
'perl' => '',
'c' => '',
'asp' => '',
'python' => '',
'bash' => '',
2015-05-06 22:24:42 +02:00
'actionscript3' => '',
2015-05-05 22:04:04 +02:00
'text' => '',
);
foreach ($types as $k => $v) {
$types[$k] = $this->translator->trans('form.type.choice.'.$k);
}
return $types;
}
}