Alter form value in submit_preprocess How do I change a value, in this case the title field of a node object form, in the preprocess function of the form_alter hook.

$form['actions']['publish']['#submit'][] = MODULE_submit_preprocess';

function MODULE_submit_preprocess($form, FormStateInterface $form_state) {

   $form_state-&gt;setValue('title', 'Updated Title'); //not working...

   $fstate = $form_state-&gt;getFormObject()-&gt;getEntity();
   dsm($fstate);
}


dsm result


stdClass Object
(
    [__CLASS__] => Drupal\node\Entity\Node
    [in_preview] =>
    [values] => Array
        (
            [title] => Array
              (
                  [x-default] => Array
                    (
                         [0] => Array
                          (
                             [value] => Old Title
To change Entities fields its better use MODULE_ENTITY_presave() function (more info in docs).

In this case that you need change a node field use this function:

function hook_node_presave(Drupal\Core\Entity\EntityInterface $entity) {
  $entity-&gt;set('title', 'Updated title');
}