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:

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';
}
  • 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'); – paulcap1 Feb 4 '17 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. – paulcap1 Feb 5 '17 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');
  }
}

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.