Co to znaczy nie dziala?
Nie dziala bo zgodnie z dokumentacja:
http://symfony.com/doc/current/reference/c...callback-optioncallback dostaje:
Concrete callbacks receive an ExecutionContextInterface instance as only argument.
Static or closure callbacks receive the validated object as the first argument and the ExecutionContextInterface instance as the second argument.Wiec Twoja metoda validate jest w dobrym miejscu (tzn moglaby byc gdzie indziej niz w form type, ale tutaj tez jest ok), ale powinna miec taka sygnature:
public function validate($value, ExecutionContextInterface $ec).
Tak jak ty masz powinienes dostac:
Catchable Fatal Error: Argument 1 passed to AppBundle\Form\TestType::validate() must implement interface Symfony\Component\Validator\Context\ExecutionContextInterface, string given
albo cos podobnego - bylby to lepszy komunikat niz "nie dziala". Jesli nie widzisz tych bledow to polecam developowac przez kontroler developerski

Dla pewnosci wysylam przykladowy form type, ktory dziala. Jesli w pole "Pole" wpiszemy "a" to formularz jest prawidlowy, a jesli b to dostaniemy blad podpiety pod pole: Pole musi byc a
<?php
namespace AppBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
class TestType extends AbstractType
{
public function buildForm
(FormBuilderInterface
$builder, array $options) {
$builder->add('pole','text',array( 'mapped' => false,
new Callback
(array($this,'validate') ))));
}
public function validate($value, ExecutionContextInterface $ec)
{
if ($value !== 'a') {
$ec->buildViolation('Pole musi byc a')
->atPath('pole')
->addViolation();
}
}
public function getName()
{
return 'test';
}
}
no i kontroler:
<?php
namespace AppBundle\Controller;
use AppBundle\Form\TestType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class DefaultController extends Controller
{
/**
* @Route("/app/example", name="homepage")
*/
public function indexAction(\Symfony\Component\HttpFoundation\Request $request)
{
$form = $this->createForm(new TestType());
$form->handleRequest($request);
if ($form->isValid()) {
}
return $this->render('default/index.html.twig', [
'form' => $form->createView(),
]);
}
}