{"action":"created","issue":{"url":"https://api.github.com/repos/symfony/symfony/issues/21111","repository_url":"https://api.github.com/repos/symfony/symfony","labels_url":"https://api.github.com/repos/symfony/symfony/issues/21111/labels{/name}","comments_url":"https://api.github.com/repos/symfony/symfony/issues/21111/comments","events_url":"https://api.github.com/repos/symfony/symfony/issues/21111/events","html_url":"https://github.com/symfony/symfony/pull/21111","id":198224180,"number":21111,"title":"[Validator] add groups support to the Valid constraint","user":{"login":"xabbuh","id":1957048,"avatar_url":"https://avatars.githubusercontent.com/u/1957048?v=3","gravatar_id":"","url":"https://api.github.com/users/xabbuh","html_url":"https://github.com/xabbuh","followers_url":"https://api.github.com/users/xabbuh/followers","following_url":"https://api.github.com/users/xabbuh/following{/other_user}","gists_url":"https://api.github.com/users/xabbuh/gists{/gist_id}","starred_url":"https://api.github.com/users/xabbuh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xabbuh/subscriptions","organizations_url":"https://api.github.com/users/xabbuh/orgs","repos_url":"https://api.github.com/users/xabbuh/repos","events_url":"https://api.github.com/users/xabbuh/events{/privacy}","received_events_url":"https://api.github.com/users/xabbuh/received_events","type":"User","site_admin":false},"labels":[{"id":100378,"url":"https://api.github.com/repos/symfony/symfony/labels/Feature","name":"Feature","color":"02e10c","default":false},{"id":237003792,"url":"https://api.github.com/repos/symfony/symfony/labels/Status:%20Needs%20Review","name":"Status: Needs Review","color":"ededed","default":false},{"id":99599,"url":"https://api.github.com/repos/symfony/symfony/labels/Validator","name":"Validator","color":"DDDDDD","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-12-31T08:31:59Z","updated_at":"2016-12-31T14:37:57Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/symfony/symfony/pulls/21111","html_url":"https://github.com/symfony/symfony/pull/21111","diff_url":"https://github.com/symfony/symfony/pull/21111.diff","patch_url":"https://github.com/symfony/symfony/pull/21111.patch"},"body":"| Q             | A\r\n| ------------- | ---\r\n| Branch?       | master\r\n| Bug fix?      | no\r\n| New feature?  | yes\r\n| BC breaks?    | no\r\n| Deprecations? | no\r\n| Tests pass?   | yes\r\n| Fixed tickets | #3622, #17622\r\n| License       | MIT\r\n| Doc PR        | TODO"},"comment":{"url":"https://api.github.com/repos/symfony/symfony/issues/comments/269867659","html_url":"https://github.com/symfony/symfony/pull/21111#issuecomment-269867659","issue_url":"https://api.github.com/repos/symfony/symfony/issues/21111","id":269867659,"user":{"login":"kgilden","id":918599,"avatar_url":"https://avatars.githubusercontent.com/u/918599?v=3","gravatar_id":"","url":"https://api.github.com/users/kgilden","html_url":"https://github.com/kgilden","followers_url":"https://api.github.com/users/kgilden/followers","following_url":"https://api.github.com/users/kgilden/following{/other_user}","gists_url":"https://api.github.com/users/kgilden/gists{/gist_id}","starred_url":"https://api.github.com/users/kgilden/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kgilden/subscriptions","organizations_url":"https://api.github.com/users/kgilden/orgs","repos_url":"https://api.github.com/users/kgilden/repos","events_url":"https://api.github.com/users/kgilden/events{/privacy}","received_events_url":"https://api.github.com/users/kgilden/received_events","type":"User","site_admin":false},"created_at":"2016-12-31T14:37:57Z","updated_at":"2016-12-31T14:37:57Z","body":"@xabbuh awesome! I confirmed it works as would validation groups work for every other constraint, i.e. in `validation.xml` you add groups to ´Valid` and now pass the `validation_groups` option when creating the form. `Valid` will only be applied if any of the groups in `validation_groups` equals those specified in `validation.xml`.\r\n\r\nHowever, I do think there is one super useful use case not covered. Consider an `Profile` object having `profilePicture` and `coverPhoto` properties - both of type `Image`, which internally has a `file` property of type `File`. Let's say we have different maximum file sizes for both of them, so we add 2 `File` constraints to the `Image` object. And both properties should be valid at all times for `Profile`.\r\n\r\n```xml\r\n<class name=\"Profile\">\r\n  <property name=\"profilePicture\">\r\n    <constraint name=\"Valid\" />\r\n  </property>\r\n  <property name=\"coverPhoto\">\r\n    <constraint name=\"Valid\" />\r\n  </property>\r\n</class>\r\n\r\n<class name=\"Image\">\r\n  <property name=\"file\">\r\n    <constraint name=\"File\">\r\n      <option name=\"maxSize\">100k</option>\r\n      <option name=\"groups\">\r\n        <value>profile-picture</value>\r\n      </option>\r\n    </constraint>\r\n    <constraint name=\"File\">\r\n      <option name=\"maxSize\">1000k</option>\r\n      <option name=\"groups\">\r\n        <value>cover-photo</value>\r\n      </option>\r\n    </constraint>\r\n  </property>\r\n</class>\r\n```\r\n\r\nIn `ProfileType` we'd have something like this probably.\r\n\r\n```php\r\n$builder->add('profilePicture', ImageType::class, ['validation_groups' => ['profile-picture]]);\r\n$builder->add('coverPhoto', ImageType::class, ['validation_groups' => ['cover-photo']);\r\n```\r\n\r\nBut try as you might, it seems to me that validation for these `File` objects does not kick in.\r\n\r\n```\r\n$form = $factory->create(ProfileType::class);\r\n$form->handleRequest($request);\r\n$form->isValid(); // returns true\r\n```\r\n"}}
{"actor":{"display_login":"kgilden"}}