How to change the label of title field bydefault its showing Title I need to change it to "Custom-title" of node edit form programatically.

I tried

 function mymodule_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if ($form_id =="slices_slices_cta_5_edit_form")


enter image description here

I just want to change [string] property of class TranslatableMarkup's object of above screen shot.

How to access the value of a Drupal\Core\StringTranslation\TranslatableMarkup object within a form

I want to do something like below example:

$form[title][widget][0]['#title']->string = t('New-title');

Not working above solution.


You can change the title label by editing the node type settings by going to Admin > Content Types > (type) > Edit. No code needed, and this can be exported to configuration.

I’m not even sure what your code is trying to do, but you don’t need it.

  • Actually we are using eck field module we need to change the title of Eck field programatically
    – user59414
    Dec 18 '17 at 13:15
  • Your question says the node edit form title needs to be changed. Why not just use the actual label of the fields?
    – Kevin
    Dec 18 '17 at 13:50