{"action":"closed","issue":{"url":"https://api.github.com/repos/Sylius/Sylius/issues/2204","repository_url":"https://api.github.com/repos/Sylius/Sylius","labels_url":"https://api.github.com/repos/Sylius/Sylius/issues/2204/labels{/name}","comments_url":"https://api.github.com/repos/Sylius/Sylius/issues/2204/comments","events_url":"https://api.github.com/repos/Sylius/Sylius/issues/2204/events","html_url":"https://github.com/Sylius/Sylius/issues/2204","id":50597927,"number":2204,"title":"[ApiBundle][Proposal] Datetime form types should be single_text","user":{"login":"steffenbrem","id":1569156,"avatar_url":"https://avatars.githubusercontent.com/u/1569156?v=3","gravatar_id":"","url":"https://api.github.com/users/steffenbrem","html_url":"https://github.com/steffenbrem","followers_url":"https://api.github.com/users/steffenbrem/followers","following_url":"https://api.github.com/users/steffenbrem/following{/other_user}","gists_url":"https://api.github.com/users/steffenbrem/gists{/gist_id}","starred_url":"https://api.github.com/users/steffenbrem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/steffenbrem/subscriptions","organizations_url":"https://api.github.com/users/steffenbrem/orgs","repos_url":"https://api.github.com/users/steffenbrem/repos","events_url":"https://api.github.com/users/steffenbrem/events{/privacy}","received_events_url":"https://api.github.com/users/steffenbrem/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Sylius/Sylius/labels/Enhancement","name":"Enhancement","color":"02d7e1"},{"url":"https://api.github.com/repos/Sylius/Sylius/labels/Feature%20Request","name":"Feature Request","color":"02e10c"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2014-12-02T00:31:09Z","updated_at":"2016-09-15T23:09:33Z","closed_at":"2016-09-15T23:09:33Z","body":"Hi,\r\n\r\nCurrently all the form types from the `CoreBundle` are used, also when processing a `POST` through an API endpoint. Some form types are still inconvenient for use in an API. For instance the `datetime` form type expects a unfriendly format, something like this:\r\n```json\r\n{\r\n    \"product\": {\r\n         \"availableOn\": {\r\n             \"time\": {\r\n                 \"hour\": 12,\r\n                 \"minute\": 30\r\n             },\r\n             \"date\": {\r\n                 \"year\": 2014,\r\n                 \"month\": 12,\r\n                 \"day\": 1\r\n             }\r\n         }\r\n    }\r\n}\r\n``` \r\n\r\nIt would be much better to have it like this (only in the API):\r\n```json\r\n{\r\n    \"product\": {\r\n         \"availableOn\": \"2014-12-01 12:30:00\"\r\n    }\r\n}\r\n``` \r\n\r\nThis could easily be done with:\r\n```php\r\n// some form type\r\n->add('datetime', array(\r\n    'widget' => 'single_text'\r\n))\r\n```\r\n\r\nCurrently I've implemented it with overriding the `CoreBundle` form types and registering them with a prefixed `api` form type (`sylius.api.form.type.product` => `sylius_api_product`). \r\n\r\nWhat would be the best way to change the form type in runtime, so that the controllers config gets the correct form type? Anyone got a good idea for it? Or should we build something around it to make it nicer. \r\n\r\nAnother way would be to check in the `CoreBundle` form types to see if it is an `API` request. Then you won't even need another form type, only side-effect then is that you get mixed logic in your form types and they need to depend on something to know if its an API request. First option seems cleaner and better to test to me.\r\n\r\n@pjedrzejewski If you like it I can make a PR for it with all the datetime form types in the `ApiBundle`."}}
{"actor":{"display_login":"steffenbrem"}}