1

I have a Drupal 8 site with the Bartik theme. How can I change label text on node add/edit form inside 'Authoring information' box. This box contains:

-Menu settings -URL path settings -Authoring information -Promotion options 

I want to rename some labels and add a new input text field. The main thing I want to change is the Authoring information box and the information inside of it. Is this done with hook form alter?

Authoring information box:

2 Answers 2

1

Those are the uid and created base fields, so yes hook_form_alter() or using interface translation are your options.

To add a new element in there, you need to set the right group, from NodeForm:

<?php if (isset($form['uid'])) { $form['uid']['#group'] = 'author'; } 
2
  • THank you. I changed the title of Authoring Information like this: $form['author']['#title'] = t('Reassign Content'); Now I neeed to change the Authored by title and the devel array looks confusing. I could do this in Drupal 7 like this: $form['author']['name']['#title'] = t('Current Author'); Commented Feb 4, 2017 at 1:17
  • Thank you Berdi, I was able to do it like this: $form['author']['#title'] = t('Reassign Content');. But I researched interface translation and it works better and translates. It can replace any text on the site even on node add/edit forms. I found that my custom hook did not translate even though I used the -t. that may be because the text is in a node add/edit form. I noticed people talking about porting the drupal 7 module stringoverrides to D8 but someone said there is no need becasue you can use interface translation. Commented Feb 5, 2017 at 14:20
1

I encountered a similar problem, and I solved it by implementing hook_form_alter().

function MYMODULE_form_alter(&$form, &$form_state, $form_id) { if ($form_id == 'node_article_edit_form' || $form_id == 'node_article_form') { $form['author']['#title'] = t('Ownership information'); $form['uid']['widget'][0]['target_id']['#title'] = t('Created by'); $form['created']['widget'][0]['value']['#title'] = t('Created on'); } } 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.