{"action":"created","issue":{"url":"https://api.github.com/repos/bolt/bolt/issues/3229","labels_url":"https://api.github.com/repos/bolt/bolt/issues/3229/labels{/name}","comments_url":"https://api.github.com/repos/bolt/bolt/issues/3229/comments","events_url":"https://api.github.com/repos/bolt/bolt/issues/3229/events","html_url":"https://github.com/bolt/bolt/pull/3229","id":63629216,"number":3229,"title":"Template specific fields","user":{"login":"Pinpickle","id":3238878,"avatar_url":"https://avatars.githubusercontent.com/u/3238878?v=3","gravatar_id":"","url":"https://api.github.com/users/Pinpickle","html_url":"https://github.com/Pinpickle","followers_url":"https://api.github.com/users/Pinpickle/followers","following_url":"https://api.github.com/users/Pinpickle/following{/other_user}","gists_url":"https://api.github.com/users/Pinpickle/gists{/gist_id}","starred_url":"https://api.github.com/users/Pinpickle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Pinpickle/subscriptions","organizations_url":"https://api.github.com/users/Pinpickle/orgs","repos_url":"https://api.github.com/users/Pinpickle/repos","events_url":"https://api.github.com/users/Pinpickle/events{/privacy}","received_events_url":"https://api.github.com/users/Pinpickle/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-03-23T05:29:19Z","updated_at":"2015-03-25T00:30:35Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/bolt/bolt/pulls/3229","html_url":"https://github.com/bolt/bolt/pull/3229","diff_url":"https://github.com/bolt/bolt/pull/3229.diff","patch_url":"https://github.com/bolt/bolt/pull/3229.patch"},"body":"PR for #2711 \r\n\r\nUse Case: You've designed an fairly complex homepage, but you want it to be really easy to edit everything. Your current setup for pages (with just one HTML field) doesn't fit into this. You either have to create a new contenttype, leverage resource contenttypes or just admit defeat and roll the changes yourself as the designer - instead of the editor. You refrain from making other pages unique and beautiful, because you know that edibility is very important.\r\n\r\nA lot of the time, we put fields in contenttypes that don't represent valuable data or information pertaining to that contenttype, but information that is relevant to how it is going to be represented (in the content). It confuses things, really, and introduces problems like I've outlined above.\r\n\r\nThis PR allows you to define fields for a template, like you would an ordinary contenttype in the theme's `config.yml`, linked to a particular template. For example:\r\n\r\n```yaml\r\ntemplate_fields:\r\n    extrafields.twig:\r\n        section_1:\r\n            type: text\r\n            label: Section 1\r\n        section_2:\r\n            type: text\r\n            label: Section 2\r\n        image:\r\n            type: image\r\n```\r\n\r\nThen, if you set that template in a record that has a template selector, you'll get a friendly notice that this will make some changes:\r\n\r\n![image](https://cloud.githubusercontent.com/assets/3238878/6774399/77be982c-d184-11e4-9933-7caef976e2f0.png)\r\n\r\nAfter saving and refreshing, the new fields appear in the \"Template\" tab.\r\n\r\n![image](https://cloud.githubusercontent.com/assets/3238878/6774406/93a3640a-d184-11e4-8594-62bae49bc8f7.png)\r\n\r\nYou can access these fields in a template as `{{ record.templatefields.field }}`\r\n\r\n```html\r\n<article>{{ record.templatefields.section_1 }}</article>\r\n<article>{{ record.templatefields.section_2 }}</article>\r\n<article>\r\n    <a href=\"{{ image(record.templatefields.image) }}\">\r\n        <img src=\"{{ thumbnail(record.templatefields.image, 640, 480) }}\">\r\n    </a>\r\n</article>\r\n```\r\n\r\n![image](https://cloud.githubusercontent.com/assets/3238878/6774646/c4406672-d188-11e4-8dd1-7d691b654f05.png)\r\n\r\nAnd it all just works.\r\n\r\nI was going to wait until the new storage layer landed, but I'm impatient. I will happily rewrite all of this functionality for that.\r\n\r\nIt works by making an extra content object that contains all of the template fields. There is an extra set of \"light\" contenttypes created in the theme's config that get set to the `templatefields` of a content object. There is now a `isRootType` for contenttypes to determine if they're a \"real\" one, or created on the fly to serve a purpose such as this.\r\n\r\n## Needs to be implemented/addressed\r\n\r\nTests! I can't get PHPUnit or Codeception to successfully run on master at the moment. I don't know if that's my fault or if there's something else going on right now. So I haven't written any tests for this behaviour. I have not yet tested manually, that every field type works.\r\n\r\nThe data stored in these fields is very fragile. By this, I mean, if you change to a different template that has different template fields, the old fields will be lost due to the nature of records not allowing fields outside of their contenttype. I do make a warning display if this is going to happen when you change templates:\r\n\r\n![image](https://cloud.githubusercontent.com/assets/3238878/6774682/62cc3afa-d189-11e4-8837-a52f7532af97.png)\r\n\r\nIt's very crude, all it does is check if a template has fields associated with it, it doesn't compare the actual fields in it.\r\n\r\nI think there are better ways this could be handled:\r\n\r\n- One could leave the data in the DB so if the template is ever returned to, the fields are restored.\r\n- Better yet, the fields that aren't active, could be displayed as readonly fields so the user could reassign content as necessary (and then mark it for deletion).\r\n- The application could \"guess\" where to reassign fields to: put HTML fields from one template into HTML fields of another (and similar with other field types)\r\n- We could adopt a common naming convention so that when you switch from one template with fields to another, there is minimal loss (there is still loss, however).\r\n\r\n## Bugfixes/refactors inbound\r\n\r\nI think at some stage during the JS refactor, server select modals stopped working if they weren't named a certain way - the name `image` still worked, so it was pretty hard to pick up on. This fixes that bug.\r\n\r\nI've changed the way fields handle rendering. Previously, they would base all of their rendering off a specific `key` variable. This worked well when there weren't arrays involved. I've split this up into three variables now:\r\n\r\n- `key`: Is the ID of the field in the form - `templatefields-image`\r\n- `name`: Is the name of the field in the form - `templatefields[image]`\r\n- `contentkey`: Is the key that we can access this value from on the content object - `image`\r\n\r\nAny older custom fields will continue to work, provided they aren't in any template specific fields.\r\n\r\nI think this is an important step to making fields more useable, as now they can be placed in any form context fairly easily.\r\n"},"comment":{"url":"https://api.github.com/repos/bolt/bolt/issues/comments/85757490","html_url":"https://github.com/bolt/bolt/pull/3229#issuecomment-85757490","issue_url":"https://api.github.com/repos/bolt/bolt/issues/3229","id":85757490,"user":{"login":"Pinpickle","id":3238878,"avatar_url":"https://avatars.githubusercontent.com/u/3238878?v=3","gravatar_id":"","url":"https://api.github.com/users/Pinpickle","html_url":"https://github.com/Pinpickle","followers_url":"https://api.github.com/users/Pinpickle/followers","following_url":"https://api.github.com/users/Pinpickle/following{/other_user}","gists_url":"https://api.github.com/users/Pinpickle/gists{/gist_id}","starred_url":"https://api.github.com/users/Pinpickle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Pinpickle/subscriptions","organizations_url":"https://api.github.com/users/Pinpickle/orgs","repos_url":"https://api.github.com/users/Pinpickle/repos","events_url":"https://api.github.com/users/Pinpickle/events{/privacy}","received_events_url":"https://api.github.com/users/Pinpickle/received_events","type":"User","site_admin":false},"created_at":"2015-03-25T00:30:35Z","updated_at":"2015-03-25T00:30:35Z","body":"@GawainLynch I'm not sure that those are the cause of the error.\r\n\r\nThe changelog test is failing, but I'm seeing an empty changelog (on master and on this branch), so I think that's where the failure is coming from.\r\n\r\nThe other failures pertaining to DB updates are coming from this error here:\r\n\r\n```\r\n<b>Deprecated</b>:  Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in <b>Unknown</b> on line <b>0</b>\r\n```\r\n\r\nThis is getting sent at some point during the DB update test, which is also sending content before the application has sent headers. Resulting in the following error:\r\n\r\n```\r\nFatal error:  Uncaught exception 'RuntimeException' with message 'Failed to start the session because headers have already been sent by \"\" at line 0.' in \r\nbolt/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php:144\r\nStack trace:\r\n#0 bolt/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php(262): Symfony\\Component\\HttpFoundation\\Session\\Storage\\NativeSessionStorage-&gt;start()\r\n#1 bolt/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/Session.php(81): Symfony\\Component\\HttpFoundation\\Session\\Storage\\NativeSessionStorage-&gt;getBag('attributes')\r\n#2 bolt/src/Application.php(219): Symfony\\Component\\HttpFoundation\\Session\\Session-&gt;has('user')\r\n#3 bolt/src/Application.php(105): Bolt\\Application-&gt;initProfiler()\r\n#4 bolt/app/bootstrap.php(82): Bolt\\Application-&gt;in in <b>bolt/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php on line 144\r\n```\r\n\r\nThis causes the DB update to fail, which means a resource contenttype isn't added so all of the other resource contenttype tests fail because there is no resource contenttype database.\r\n\r\nI don't get this issue when adding them manually.\r\n\r\nThese are both issues I'm getting in master, so maybe its something to do with my setup?"}}