Created
July 11, 2012 14:24
-
-
Save webmozart/3090686 to your computer and use it in GitHub Desktop.
Issue 2677
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 | |
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()); | |
} | |
} |
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 | |
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!'); | |
} | |
} |
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
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