Skip to content

Instantly share code, notes, and snippets.

@webmozart
Created July 11, 2012 14:24
Show Gist options
  • Save webmozart/3090686 to your computer and use it in GitHub Desktop.
Save webmozart/3090686 to your computer and use it in GitHub Desktop.
Issue 2677
<?php
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
/**
* https://github.com/symfony/symfony/issues/2677
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class Issue2677Controller extends Controller
{
/**
* @Route("/2677", name="issue2677")
* @Template()
*/
public function testAction(Request $request)
{
$entity = new Issue2677Entity();
$form = $this->createFormBuilder($entity, array(
'validation_groups' => array('admin_context'),
))
->add('name')
->add('lastName')
->add('nicePerson', 'checkbox')
->getForm();
if ('POST' === $request->getMethod()) {
$form->bind($request);
}
return array('form' => $form->createView());
}
}
<?php
use Symfony\Component\Validator\ExecutionContext;
class Issue2677Entity
{
public $name;
public $lastName;
public $nicePerson;
public function isNicePerson()
{
return $this->nicePerson;
}
public function setNicePerson($nicePerson)
{
$this->nicePerson = $nicePerson;
}
public function PersistOnlyOnWeekend(ExecutionContext $context)
{
$context->addViolationAtSubPath('name', 'Check failed!');
}
}
Issue2677Entity:
properties:
name:
- NotBlank: { groups: [ admin_context ] }
lastName:
- NotBlank: ~
getters:
nicePerson:
- 'True': { message: 'You are not a nice person', groups: [ admin_context ] }
constraints:
- Callback:
methods: [ PersistOnlyOnWeekend ]
groups: [ admin_context ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment