How to modify the subfields of a custom field in hook presave I have a custom field in a custom module that consists of 4 varchar type values. Each of these subfields are called 'prefix', 'suffix', 'body' and 'header'.
In the hook presave, I want to modify only one of them, 'prefix', however, I can't do it:
function custom_field_entity_presave(Drupal\Core\Entity\EntityInterface $entity) {
  switch ($entity-&gt;bundle()) {
    case 'custom_object':
      //This seems to modify all de field instead only the subfield 'prefix'
      $entity-&gt;set('field_multifield', ['prefix' =&gt; '55555']);
      break;
  }
}
As @sonfd commented you could get the field content as array:
$values = $entity-&gt;get('field_multifield')-&gt;getValue();

modify this array
$values[0]['prefix'] = '55555';

and then replace the entire field content:
$entity-&gt;set('field_multifield', $values);

Much easier though would be accessing a single property directly:
$entity-&gt;field_multifield-&gt;prefix = '55555';