2

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?

1 Answer 1

4

After several trial and errors this is the code working:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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