my_module.module
$field_render_array = $entity->{$field_name}->view([
'type' => 'default_formatter', // Replace with desired formatter type.
'label' => 'hidden', // If you want to hide the label of the field (optional).
'settings' => [
'trim_length' => 100, // Example for textfields: Trim the text to 100 characters.
],
]);
12.12.2025 | Michael Ebert