Closed finnlewis closed 2 months ago
Shall we write an update hook then?
Anyone got an example of loading a view from a config file and updating it in an update hook?
Shall we write an update hook then?
Anyone got an example of loading a view from a config file and updating it in an update hook?
Oh I do I think.
This one is from the last version of the module which could be repurposed:
/**
* Update views that were missing validation.
*/
function localgov_elections_reporting_update_9002() {
$module_path = \Drupal::getContainer()
->get('module_handler')
->getModule('localgov_elections_reporting')
->getPath();
$config_to_update = [
'views.view.electoral_candidates',
...
];
$install_dir = new FileStorage($module_path . '/config/install/');
foreach ($config_to_update as $config){
$data = $install_dir->read($config);
$config_obj = \Drupal::configFactory()->getEditable($config);
$config_obj->setData($data);
$config_obj->save(TRUE);
}
Drupal::logger('localgov_elections_reporting')->notice("Updated views with validation");
drupal_flush_all_caches();
}
It just needs adjusted for a single view. Only issue with this approach is that it could overwrite a user's changes but I think it's okay given we're still in beta.
@finnlewis I've added the update hook. Let me know if you're happy with it so we can merge.
…ame.
See #92