2
votes

I'm trying to auto-fill the title a content creation form in Drupal 8 with the user ID of the person creating the node, but I can't seem to get past step 1, which is having the title default to anything. I've made a module and added this code to it:

function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == "new_content_type_node_form") {
    $form['title']['#default_value'] = 'Test12';
  }
}

On the creation screen I'm using dpm to look at the $form var, and it's showing that the title does have a value in #default_value, and it is Test12, but when the form renders the title field is blank.

It seems like the way to do this in Drupal 7 and earlier was drupal_set_title(), but I can't find the equivalent for Drupal 8. Any ideas?

1

1 Answers

4
votes

Solved by digging a little deeper into the form array:

$form['title']['widget'][0]['value']['#default_value'] = 'Test12';