Created
February 10, 2016 16:42
-
-
Save ABM-Dan/3bdd9c6216fee257737b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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