In my Drupal 8 project I tried to find a way to add a description to the title field of a node form by hook_form_alter. Following code(s) did not lead to success:

$form['title']['widget'][0]['#description'] =  \Drupal\Core\Field\FieldFilteredMarkup::create('hallo');
$form['title']['widget']['#description'] =  \Drupal\Core\Field\FieldFilteredMarkup::create('hallo');
$form['title']['#description'] =  \Drupal\Core\Field\FieldFilteredMarkup::create('hallo');

What is the correct place to define a description for the node title field?


After several trial and errors this is the code working:

$form['title']['widget'][0]['value']['#description'] =  \Drupal\Core\Field\FieldFilteredMarkup::create('hallo');
  • This works, but seems quite convoluted. I wonder if there's an explanation of this somewhere. – Brian Nov 21 '16 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.