If I release a new version of a module, and want to include new configuration in the new version (particularly new fields, and updates to views to rely on those fields) by either making Drupal update the config.whatever.yml files, or writing something in hook_update_N() that will install them, how could I do it? I would want to make sure it only installs the new fields if they don't already exist, since I would want to include the fields' yaml files.
Or, should I require features and use that for adding new fields?
It's confusing to me, because I want to include a config.yml that has the most recent config information, right? Yet, I want to update anyone already using the module by installing the new fields that they don't have.
EDIT 2:
Okay, no, never mind. Don't use the below code. I thought it worked, but really the fields were just installed via the yml files when I installed the module. I don't know why I didn't realize that would happen. My update function never really ran. When I retried it the correct way, it failed, because FieldConfigStorage can't be loaded in this way. I still don't know how to install fields in a way that will create the tables.
EDIT:
The code resulting from Berdir's example:
// Don't forget to include a use-statement if you haven't already:
use Symfony\Component\Yaml\Yaml;
function some_module_update_8101() {
$message = "";
if ( !FieldConfig::load('example_field') ){
$config_path = drupal_get_path('module', 'some_module') . '/config/install/field.field.node.some_node_type.field_example_field.yml';
$data = Yaml::parse($config_path);
\Drupal::configFactory()->getEditable('field.field.node.some_node_type.field_example_field')->setData($data)->save(TRUE);
$message .= "FieldConfig installed for module some_module.\n";
}
else {
$message .= "It didn't work!\n";
}
if( !FieldConfigStorage::load('example_field') ){
$config_path = drupal_get_path('module', 'some_module') . '/config/install/field.storage.node.field_example_field.yml';
$data = Yaml::parse($config_path);
\Drupal::configFactory()->getEditable('field.storage.node.field_example_field')->setData($data)->save(TRUE);
$message .= "FieldConfigStorage installed for module some_module.\n";
}
else{
$message .= "That didn't work either!\n";
}
return $message;
}