add taxonomies to update hook
This commit is contained in:
@@ -2,21 +2,39 @@
|
|||||||
* Updates allowed taxonomy types.
|
* Updates allowed taxonomy types.
|
||||||
*/
|
*/
|
||||||
function farm_agrikern_update_1(&$sandbox) {
|
function farm_agrikern_update_1(&$sandbox) {
|
||||||
// Updates field storage config for field_custom_radio_buttons.
|
<!-- $old_config = FieldStorageConfig::loadByName('log', 'work_field');
|
||||||
// @see https://www.drupal.org/node/2012896
|
|
||||||
// @see https://www.drupal.org/docs/8/api/update-api/updating-entities-and-fields-in-drupal-8#example-updating-a-field-from-an-obsolete-type-to-a-new-type
|
|
||||||
$old_config = FieldStorageConfig::loadByName('asset', 'crop_field');
|
|
||||||
$new_config = $old_config->createDuplicate();
|
|
||||||
$new_config->original = $new_config;
|
|
||||||
$new_config->enforceIsNew(FALSE);
|
|
||||||
$new_config
|
|
||||||
->setSetting('target_bundle', 'plant_type')
|
|
||||||
->save();
|
|
||||||
$old_config = FieldStorageConfig::loadByName('log', 'work_field');
|
|
||||||
$new_config = $old_config->createDuplicate();
|
$new_config = $old_config->createDuplicate();
|
||||||
$new_config->original = $new_config;
|
$new_config->original = $new_config;
|
||||||
$new_config->enforceIsNew(FALSE);
|
$new_config->enforceIsNew(FALSE);
|
||||||
$new_config
|
$new_config
|
||||||
->setSetting('target_bundle', 'work_type')
|
->setSetting('target_bundle', 'work_type')
|
||||||
->save();
|
->save(); -->
|
||||||
|
$config_ids = [
|
||||||
|
'taxonomy.vocabulary.chemical',
|
||||||
|
'taxonomy.vocabulary.work_type',
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($config_ids as $config_id) {
|
||||||
|
// Check if the configuration already exists.
|
||||||
|
$existing_config = \Drupal::config($config_id);
|
||||||
|
if ($existing_config->isNew()) {
|
||||||
|
// Load the YAML file from the module's config/install directory.
|
||||||
|
$config_storage = \Drupal::service('config.storage');
|
||||||
|
$data = $config_storage->read($config_id);
|
||||||
|
|
||||||
|
if ($data) {
|
||||||
|
// Import the configuration.
|
||||||
|
$config_importer = \Drupal::service('config.installer');
|
||||||
|
$config_importer->create($config_id, $data);
|
||||||
|
\Drupal::messenger()->addMessage("Configuration '{$config_id}' imported.");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
\Drupal::messenger()->addMessage("Configuration file for '{$config_id}' not found.", 'error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
\Drupal::messenger()->addMessage("Configuration '{$config_id}' already exists.", 'warning');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user