Insert Revision log message programmatically after form submission I am trying to pragmatically set the revision log message after values of certain fields are changed (thus if a user has edits certain fields). More information is in the code comments

 function home_hub1_form_alter(&amp;$form, FormStateInterface $form_state, $form_id){


//    Hide Revisions log message text box
$form['revision_log_message']['#access']= FALSE;

//set revision check box to false since we are creating a revision progeammatically
$form['new_revision'] = array(
    '#type' =&gt; 'hidden',
    '#value' =&gt; FALSE
);

// monitor every field if its from edit
if ($form_id == 'device_entity_edit_form'){

    $form['actions']['submit']['#submit'][] = 'home_hub1_form_device_entity_edit_submit';

  }
} 

function home_hub1_form_device_entity_edit_submit(array &amp;$form, FormStateInterface $form_state){

$form_state-&gt;setTemporaryValue('entity_validated', TRUE);

//check if a field has changed and if it has write a revision log message
if ($form['field_city']['widget']['0']['value']['#value'] != $form['field_city']['widget']['0']['value']['#default_value']) {

    $message = 'CITY changed from: ' . $form['field_city']['widget']['0']['value']['#default_value'] . ' to: ' . $form['field_city']['widget']['0']['value']['#value'];

   $form_state-&gt;setValue('revision_log_message', $message);


}


I am getting the following error: Error: Cannot unset string offsets in Drupal\Core\Field\WidgetBase-&gt;extractFormValues()

I also tried to get the node object so that i create a revision directly from it like below:

function home_hub1_form_device_entity_edit_submit(array &amp;$form, FormStateInterface $form_state){

$node = $form_state-&gt;getFormObject()-&gt;getEntity();

//check if a field has changed and if it has write a revision log message
if ($form['field_city']['widget']['0']['value']['#value'] != $form['field_city']['widget']['0']['value']['#default_value']) {

$message = 'CITY changed from: ' . $form['field_city']['widget']['0']['value']['#default_value'] . ' to: ' . $form['field_city']['widget']['0']['value']['#value'];

  $node-&gt;setRevisionUserId(\Drupal::currentUser()-&gt;id());
  $node-&gt;setRevisionCreationTime(REQUEST_TIME);
  $node-&gt;setNewRevision(TRUE); // enabling revision for the entity save.
  $node-&gt;setRevisionLogMessage($message);


}

How can I create a revision after form submission?
I found the solution. I should have used hook_form_BASE_FORM_ID_alter() instead of hook_form_FORM_ID_alter

Also the call back function should be  home_hub1_my_entity_builder