function name_update_8203 in Name Field 8
Loads the name generator services files into the active configuration.
File
- ./
name.install, line 78 - Standard installation functions for name.
Code
function name_update_8203() {
$config_factory = \Drupal::configFactory();
$config_path = drupal_get_path('module', 'name') . '/config/install/name.generate.components.yml';
$data = Yaml::parse(file_get_contents($config_path));
$config = $config_factory
->getEditable('name.generate.components');
$config
->set('components', $data['components']);
$config
->set('gender', $data['gender']);
$config
->save(TRUE);
$config_path = drupal_get_path('module', 'name') . '/config/install/name.generate.preferred.yml';
$data = Yaml::parse(file_get_contents($config_path));
$config = $config_factory
->getEditable('name.generate.preferred');
$config
->set('preferred', $data['preferred']);
$config
->save(TRUE);
if ($examples = $config_factory
->get('name.examples.default')
->get('examples')) {
$config = $config_factory
->getEditable('name.generate.examples');
if (!empty($examples[0]['title'])) {
$examples[0] += [
'preferred' => 'Joe',
'alternative' => 'Lorem ipsum dolor',
];
}
$config
->set('examples', $examples);
$config
->save(TRUE);
$old_config = $config_factory
->getEditable('name.examples.default');
$old_config
->delete();
}
else {
$config_path = drupal_get_path('module', 'name') . '/config/install/name.generate.examples.yml';
$data = Yaml::parse(file_get_contents($config_path));
$config = $config_factory
->getEditable('name.generate.examples');
$config
->set('examples', $data['examples']);
$config
->save(TRUE);
}
}