Skip to content

Instantly share code, notes, and snippets.

@ABM-Dan
Created February 10, 2016 16:42
Show Gist options
  • Save ABM-Dan/3bdd9c6216fee257737b to your computer and use it in GitHub Desktop.
Save ABM-Dan/3bdd9c6216fee257737b to your computer and use it in GitHub Desktop.
<?php
namespace MyBundle\Form\Type;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints as Assert;
class MyFormType extends AbstractType implements ContainerAwareInterface
{
use \Symfony\Component\DependencyInjection\ContainerAwareTrait;
public function buildForm(FormBuilderInterface $builder, array $options)
{
$translator = $this->container->get('translator');
$builder->add('my-field', 'text', [
'constraints' => [
new Assert\NotBlank([
'message' => $translator->trans('%field% should not be blank.', ['%field%' => $translator->trans('MyFieldName')]),
]),
],
]);
}
public function getName()
{
return 'my_form';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment