getBundleInfo($type); $machine_names = array_keys($bundles); $bundle_names[$type] = $machine_names; } // Get all custom fields that are "text_long" fields. foreach ($bundle_names as $type => $machine_names) { foreach ($machine_names as $machine_name) { $bundle_fields = \Drupal::service('entity_field.manager')->getFieldDefinitions($type, $machine_name); foreach ($bundle_fields as $field_name => $field) { $current_field_type = $field->getFieldStorageDefinition()->getType(); if (str_starts_with($field_name, "field_") && $current_field_type === $field_type) { $fields[$type][] = $field_name; } // Add "body" core field if (str_starts_with($field_name, "body") && $current_field_type === $field_type) { $fields[$type][] = $field_name; } // Add "description" core field if (str_starts_with($field_name, "description") && $current_field_type === $field_type) { $fields[$type][] = $field_name; } } } if (isset($fields[$type])) { $unique_fields[$type] = array_unique($fields[$type]); } } // Alter field tables foreach ($unique_fields as $type => $fields) { foreach ($fields as $field) { $tables = [ $type . "__" . $field, $type . "_revision__" . $field, ]; $column = $field . "_format"; foreach ($tables as $table) { $update_field = $database->update($table) ->condition($column, $old_format, "=") ->fields([$column => $new_format]) ->execute(); } } }