function entity_reference_revisions_field_storage_config_update in Entity Reference Revisions 8
Implements hook_ENTITY_TYPE_update() for 'field_storage_config'.
Reset the instance handler settings, when the target type is changed.
File
- ./
entity_reference_revisions.module, line 63 - Provides a field that can reference other entities.
Code
function entity_reference_revisions_field_storage_config_update(FieldStorageConfigInterface $field_storage) {
if ($field_storage
->getType() != 'entity_reference_revisions') {
// Only act on entity reference fields.
return;
}
if ($field_storage
->isSyncing()) {
// Don't change anything during a configuration sync.
return;
}
if ($field_storage
->getSetting('target_type') == $field_storage->original
->getSetting('target_type')) {
// Target type didn't change.
return;
}
if (empty($field_storage->bundles)) {
// Field storage has no fields.
return;
}
$field_name = $field_storage
->getName();
foreach ($field_storage
->bundles() as $entity_type => $bundles) {
foreach ($bundles as $bundle) {
$field = FieldConfig::loadByName($entity_type, $bundle, $field_name);
$field
->setSetting('handler_settings', []);
$field
->save();
}
}
}