{"action":"created","issue":{"url":"https://api.github.com/repos/pencilblue/pencilblue/issues/1097","repository_url":"https://api.github.com/repos/pencilblue/pencilblue","labels_url":"https://api.github.com/repos/pencilblue/pencilblue/issues/1097/labels{/name}","comments_url":"https://api.github.com/repos/pencilblue/pencilblue/issues/1097/comments","events_url":"https://api.github.com/repos/pencilblue/pencilblue/issues/1097/events","html_url":"https://github.com/pencilblue/pencilblue/issues/1097","id":166260439,"number":1097,"title":"How to add a new field in Article adding page","user":{"login":"IsisPr0","id":20531877,"avatar_url":"https://avatars.githubusercontent.com/u/20531877?v=3","gravatar_id":"","url":"https://api.github.com/users/IsisPr0","html_url":"https://github.com/IsisPr0","followers_url":"https://api.github.com/users/IsisPr0/followers","following_url":"https://api.github.com/users/IsisPr0/following{/other_user}","gists_url":"https://api.github.com/users/IsisPr0/gists{/gist_id}","starred_url":"https://api.github.com/users/IsisPr0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IsisPr0/subscriptions","organizations_url":"https://api.github.com/users/IsisPr0/orgs","repos_url":"https://api.github.com/users/IsisPr0/repos","events_url":"https://api.github.com/users/IsisPr0/events{/privacy}","received_events_url":"https://api.github.com/users/IsisPr0/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/pencilblue/pencilblue/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":{"login":"brianhyder","id":3628887,"avatar_url":"https://avatars.githubusercontent.com/u/3628887?v=3","gravatar_id":"","url":"https://api.github.com/users/brianhyder","html_url":"https://github.com/brianhyder","followers_url":"https://api.github.com/users/brianhyder/followers","following_url":"https://api.github.com/users/brianhyder/following{/other_user}","gists_url":"https://api.github.com/users/brianhyder/gists{/gist_id}","starred_url":"https://api.github.com/users/brianhyder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brianhyder/subscriptions","organizations_url":"https://api.github.com/users/brianhyder/orgs","repos_url":"https://api.github.com/users/brianhyder/repos","events_url":"https://api.github.com/users/brianhyder/events{/privacy}","received_events_url":"https://api.github.com/users/brianhyder/received_events","type":"User","site_admin":false},"assignees":[{"login":"brianhyder","id":3628887,"avatar_url":"https://avatars.githubusercontent.com/u/3628887?v=3","gravatar_id":"","url":"https://api.github.com/users/brianhyder","html_url":"https://github.com/brianhyder","followers_url":"https://api.github.com/users/brianhyder/followers","following_url":"https://api.github.com/users/brianhyder/following{/other_user}","gists_url":"https://api.github.com/users/brianhyder/gists{/gist_id}","starred_url":"https://api.github.com/users/brianhyder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brianhyder/subscriptions","organizations_url":"https://api.github.com/users/brianhyder/orgs","repos_url":"https://api.github.com/users/brianhyder/repos","events_url":"https://api.github.com/users/brianhyder/events{/privacy}","received_events_url":"https://api.github.com/users/brianhyder/received_events","type":"User","site_admin":false}],"milestone":null,"comments":1,"created_at":"2016-07-19T06:52:33Z","updated_at":"2016-07-19T13:03:55Z","closed_at":null,"body":"**Description:**\r\nI need to add a new field, but data from this field are not added to the database.\r\nWhat I've done:\r\n1. Path: \r\n   plugins\\pencilblue\\templates\\admin\\content\\article_form.html\r\n   Code:\r\n   <div class=\"form-group\">\r\n\t<label>^loc_TEST_FIELD^</label>\r\n\t<input type=\"text\" class=\"form-control\" ng-model=\"article.testtext\">\r\n   </div>\r\n2. Path:\r\n  plugins\\pencilblue\\templates\\angular\\admin\\content\\article_form.html\r\n  Code:\r\n  articleData.draft = draft ? 1 : 0;\r\n  /* NEW */          \r\n  articleData.testtext = $scope.article.testtext.toString();\r\n  /* #END NEW */\t\t\t\r\n  var media = [];\r\n\r\nWhat should I do to the data from this field is added to the database?\r\n\r\n**Steps to Reproduce:**\r\n\r\n\r\n**Configuration Details:**\r\n\r\n\r\n**Log Output:**\r\n\r\n\r\nPencilBlue Version: \r\n0.5.1\r\nNode.js Version:\r\n\r\nEnvironment Description:\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/pencilblue/pencilblue/issues/comments/233625545","html_url":"https://github.com/pencilblue/pencilblue/issues/1097#issuecomment-233625545","issue_url":"https://api.github.com/repos/pencilblue/pencilblue/issues/1097","id":233625545,"user":{"login":"brianhyder","id":3628887,"avatar_url":"https://avatars.githubusercontent.com/u/3628887?v=3","gravatar_id":"","url":"https://api.github.com/users/brianhyder","html_url":"https://github.com/brianhyder","followers_url":"https://api.github.com/users/brianhyder/followers","following_url":"https://api.github.com/users/brianhyder/following{/other_user}","gists_url":"https://api.github.com/users/brianhyder/gists{/gist_id}","starred_url":"https://api.github.com/users/brianhyder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brianhyder/subscriptions","organizations_url":"https://api.github.com/users/brianhyder/orgs","repos_url":"https://api.github.com/users/brianhyder/repos","events_url":"https://api.github.com/users/brianhyder/events{/privacy}","received_events_url":"https://api.github.com/users/brianhyder/received_events","type":"User","site_admin":false},"created_at":"2016-07-19T13:03:55Z","updated_at":"2016-07-19T13:03:55Z","body":"Hey @IsisPr0, great question.  Earlier versions of PB allowed this functionality.  However, what we realized was that it created a security hole to allow for any and all fields to be passed back and persisted through the API.  It also encouraged poor coding practices because the developers were not validating the input that the UI was providing.  \r\n\r\nTo correct the issue, we created the BaseObjectService.  It emits a number of events that allow for developers to hook in and allow for extra fields.  The ArticleServiceV2 utilizes this functionality.  You will need to do the following in your plugin's main module file's onStartupWithContext.\r\n\r\n1. Subscribe to the FORMAT event. This is where you will sanitize the input for custom field you would like to add\r\n2. Subscribe to the MERGE event.  This is where you will merge the value provided by the incoming request into the object to be persisted\r\n3. subscribe to the VALIDATE event.  This is where you will ensure that the field meets any requirements (required, length, format, etc.).\r\n\r\nExample:\r\nhttps://github.com/pencilblue/pencilblue/blob/master/plugins/sample/services/book_service.js#L301\r\nIn the above example you will need to replace ```TYPE``` with ```article``` and provide your own handlers.  However, the example does show the parameters available and a general guideline for implementation.\r\n\r\nThis will allow you to persist the new field and ensure that it is not compromised.  "}}
{"actor":{"display_login":"brianhyder"}}