{"action":"closed","issue":{"url":"https://api.github.com/repos/backdrop/backdrop-issues/issues/2434","repository_url":"https://api.github.com/repos/backdrop/backdrop-issues","labels_url":"https://api.github.com/repos/backdrop/backdrop-issues/issues/2434/labels{/name}","comments_url":"https://api.github.com/repos/backdrop/backdrop-issues/issues/2434/comments","events_url":"https://api.github.com/repos/backdrop/backdrop-issues/issues/2434/events","html_url":"https://github.com/backdrop/backdrop-issues/issues/2434","id":197767491,"node_id":"MDU6SXNzdWUxOTc3Njc0OTE=","number":2434,"title":"Writing update hooks that create new views.","user":{"login":"klonos","id":2423362,"node_id":"MDQ6VXNlcjI0MjMzNjI=","avatar_url":"https://avatars1.githubusercontent.com/u/2423362?v=4","gravatar_id":"","url":"https://api.github.com/users/klonos","html_url":"https://github.com/klonos","followers_url":"https://api.github.com/users/klonos/followers","following_url":"https://api.github.com/users/klonos/following{/other_user}","gists_url":"https://api.github.com/users/klonos/gists{/gist_id}","starred_url":"https://api.github.com/users/klonos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/klonos/subscriptions","organizations_url":"https://api.github.com/users/klonos/orgs","repos_url":"https://api.github.com/users/klonos/repos","events_url":"https://api.github.com/users/klonos/events{/privacy}","received_events_url":"https://api.github.com/users/klonos/received_events","type":"User","site_admin":false},"labels":[{"id":54904568,"node_id":"MDU6TGFiZWw1NDkwNDU2OA==","url":"https://api.github.com/repos/backdrop/backdrop-issues/labels/status%20-%20duplicate","name":"status - duplicate","color":"c7def8","default":false},{"id":54904571,"node_id":"MDU6TGFiZWw1NDkwNDU3MQ==","url":"https://api.github.com/repos/backdrop/backdrop-issues/labels/type%20-%20question","name":"type - question","color":"cc317c","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-12-27T22:41:15Z","updated_at":"2019-01-04T21:08:00Z","closed_at":"2019-01-04T21:08:00Z","author_association":"MEMBER","body":"This is a generic question on which is the most appropriate way to go about doing this. I noticed that in https://github.com/backdrop/backdrop/pull/573 (for #150) and in https://github.com/backdrop/backdrop/pull/615 (for #149) we created the `views.view.*.json` files under the respective module `/config` directory, and then we also (re)created the same views in the respective .install files, inside the update hooks by using arrays and then doing:\r\n\r\n```\r\n$config->setData($array_holding_the_view_config);\r\n$config->save();\r\n```\r\n\r\nNow in https://github.com/backdrop/backdrop/pull/1539 (for #1042) and in https://github.com/backdrop/backdrop/pull/1690 (for #2422), we did the same things when it comes to creating the default .json files for the views inside the `/config` directories, but in the update hooks instead of re-creating the same view configs in arrays, we read them from the .json files, then decode the .json files and then save config:\r\n\r\n```\r\n$config = config('views.view.view_name');\r\n  if ($config->isNew()) {\r\n    $path = backdrop_get_path('module', 'module_name') . '/config/';\r\n    $contents = file_get_contents($path . 'views.view.view_name.json');\r\n    $data = json_decode($contents, true);\r\n    $config->setData($data);\r\n    $config->save();\r\n```\r\n\r\nThe second way seems cleaner to me and the update hook code is much shorter and not \"polluted\" by repeating the entire view .json in an array format.\r\n\r\nSo, the question: is there any specific reason why we did things the way we did them in the first two PRs? And does it make sense to correct those update hooks in order to make them more readable for future developers going through the code? ...I mean there's also the chance that some beginner coders might happen to come across these update hooks and use them as examples. They will go through all the trouble doing things that way only to have a reviewer point them to the easier/cleaner one and ask them to re-do everything."}}
{"actor":{"display_login":"klonos"}}