0

In Drupal 7 this was pretty easy. But now when I try to change the term name label on the term add/edit form all I find are protected methods.

/**
 * Implements hook_form_alter().
 */
function MYMODULE_form_alter(&$form, FormStateInterface $form_state, $form_id) {

  if ($form_id == 'taxonomy_MYVOCABULARY_form') {
    ksm($form['name']);
    // ?????
  }
}

This is no translation issue.

  • Just a question, are you using multilanguage setup ? – O V Mar 24 '17 at 13:03
  • @OlegVidenov - Single language. This is no translation issue. – leymannx Mar 24 '17 at 13:04
2

If you mean you want to change the title of the form element, then it is basically the same as it was in 7.x.

/**
 * Implements hook_form_alter().
 */
function MYMODULE_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  if ($form_id == 'taxonomy_MYVOCABULARY_form') {
    $form['foo']['#title'] = t('New Title');
  }
}

Adding in what 4k4 said... field widgets behave differently than general form items:

$form['name']['widget'][0]['value']['#title'] = 'New Title';
  • Of couse, this was the first thing I tried. But it doesn't seem to be so simple anymore. At least in the term edit form. – leymannx Mar 24 '17 at 13:16
  • 1
    If the field has a widget: $form['name']['widget'][0]['value']['#title'] = 'New Title'; – 4k4 Mar 24 '17 at 13:40
  • @4k4 – It works but I wouldn't have excepted this as ksm($form['name']['widget'][0]['value']['#title']) only returns me some methods. None of them lets me set anything. – leymannx Mar 24 '17 at 13:56
  • 1
    @leymannx, what you see is a translatable markup object, the result of the t() function. You can't change it, only replace it with a new t('New Title'). – 4k4 Mar 24 '17 at 16:30

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.