Validating a node body hello i am trying to validate the content of the node body for certain text having some trouble with it. it outputs an message "array".

function test_form_alter(&amp;$form, FormStateInterface $form_state) {
  // Custom validate function.
  $form['#validate'][] = 'submitForm';
}

function submitForm(array &amp;$form, FormStateInterface $form_state) {
  $author = $form_state-&gt;getValue('author');
  $body = $form_state-&gt;getValue('body');
  $title = $form_state-&gt;getValue('title');
  drupal_set_message('Thanks for submitting the form! you typed in the following as author:' . $author . ' . body:' . $body . '. title:' . $title);
}
You get the outputs message as an array, because you supplied $body and $title as arrays, and $form_state-&gt;getValue('author'); doesn't give you author of node test with the following code:

function test_form_alter(&amp;$form, FormStateInterface $form_state) {
  // Custom validate function.
  $form['#validate'][] = 'validateForm';
}

function validateForm(array &amp;$form, FormStateInterface $form_state) {
  //- Get the author id.
  $author_uid = $form_state-&gt;getValue('uid')[0]['target_id'];
  // Load the author account.
  $author = User::load($author_uid);
  //- Get the body value, if you want just the summary change value by summary. 
  $body = $form_state-&gt;getValue('body')[0]['value'];
  //- Get the title value .
  $title = $form_state-&gt;getValue('title')[0]['value'];
  //- Use addMessage instead of drupal_set_message its deprecated.
  \Drupal::messenger()-&gt;addMessage('Thanks for submitting the form! you typed in the following as author:' . $author-&gt;getAccountName() . ' . body:' . $body . '. title:' . $title);
}


Don't forget to add the following use:

use Drupal\Core\Form\FormStateInterface;
use Drupal\user\Entity\User;