Lately I had to prefill values on an entity form. Somewhat it did not work directly. Here is a working snippet.

$form['title']['widget'][0]['value']['#value'] = 'The default title';

// To prevent editing
$form['title']['#disabled'] = TRUE;
// To hide is as well
$form['title']['#access'] = FALSE;





Saved you some valuable time?


Donate and get more free time-saving code on this website in the future.