Hello,

I need to change the text of the "Save" button of a node creation form of a certain content type (form is displayed in front-office). I tried this preprocess function :

function mytheme_my_content_type_form_alter(&$variables, &$form){
  if ( isset($form['actions']['publish']) ) {
    $form['actions']['publish']['#value'] = 'Submit';
  }
}

I'm kinda stuck here...

Thanks for your help !

Comments

Jeff Burnz’s picture

You can't do this in preprocess, and btw what you have above is an "alter" (albeit with incorrect parameters), so you're mostly on the right track.

I would use a strait form alter because for node forms there are two ID's, one for the add form and one for the edit form. You can study the form array by installing the Devel module and using the kint() function to print it all out nicely on the page.

// HOOK is your theme or module name.
function HOOK_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  //kint($form);
  if ($form_id === 'node_article_form' || $form_id === 'node_article_edit_form') {
    $form['actions']['publish']['#value'] = t('Submit');
  }
}

https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Form%21fo...