1

We have an existing custom module for our Drupal 8 application that created a content type and a view. The "news" module is in our production environment running fine; many pieces of content have been created using it.

Now enhancements have been requested: 2 new fields and a change to the view. I have made the changes using the admin UI in our dev environment, but I will need to put these changes into the module's code for version control so that in new site instances, one need not remember to make UI changes after installing the module.

The fields:
field_show_on_page, Field Type: List (text)
field_news_dateline, Field Type: Date
View:
The change in the view is on what field the sorting is done.

It would be simple to export the fields and view configurations and add them to the module>config >install folder, but for the change to be picked up, that requires uninstalling and reinstalling the module, which can't be done without needing to delete news content, which is not acceptable.

I understand the changes can be done in hook_update_N in the news.install file. But I cannot find examples for this function that is close enough for this need. I understand the function should be written as:

news_update_8001() {}

But what would go in the body to add the two fields and update the view?

closed as too broad by kiamlaluno Aug 21 '17 at 16:52

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • I was able to find relevant code in a contrib module for adding the new fields. Still need to find a way to update the view via code. – J Cane Aug 18 '17 at 17:01

Browse other questions tagged or ask your own question.