Hi all,

I'm using IEF with entities of type nodes, so my submit text is "Add new node".

How to change this text?

I've tried with hook_form_alter() in this way:

function helper_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'my_node_type_node_form':
      $form['field_step_page']['und']['actions']['ief_add']['#value'] == t('Add new step');
      break;
  }
}

but text doesn't change.

Thank you for any help

Comments

bojanz’s picture

Status: Active » Fixed

You can replace the controller for nodes like shown in http://drupal.org/node/1521274#comment-6738984 and override the labels() method.

Your form alter looks fine at a glance so I don't know why it's failing, you'll have to debug it.

technotim2010’s picture

Hi

I have the same issue as MXT and tried more or less the same solution using hook_form_alter

function eventsresults_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case 'events_node_form':
      $form['field_runner_times']['und']['actions']['ief_add']['#value'] = t('Add Runner Times');
      break;
  }
}

Note I used = on line 4 rather than == (which is a logical comparison operator is it not?) and hey ho I get success the button now reads "Add Runner Times"

I hope that helps someone else esp MXT

Tim

mxt’s picture

Yes Tim: you discovered the error: thank you!

Can I ask you if you also have successfully altered the "save node" button WITHIN the ajax loaded referenced entity form? dpm($form) does not work with ajax in the way...

mxt’s picture

Ok, I've got it, so, to resume:

function helper_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'my_node_type_node_form':
      $form['field_step_page']['und']['actions']['ief_add']['#value'] = t('Add new step');
      $form['field_step_page']['und']['form']['#title'] = t('Add new step page');
      $form['field_step_page']['und']['form']['actions']['ief_add_save']['#value'] = t('Save step);
      break;
  }
}

MXT

technotim2010’s picture

Hi
So to sum up just for those seeking this answer and to make it nice and simple for them (I recall too much head scratching trying to incorporate a solution only partly listed)

If you are adding multiple values of another content type using entity reference and entity inline form it adds the "add node" button/link and this we can override with the hook_form_alter using the code

 $form['field_your_field_name']['und']['actions']['ief_add']['#value'] = t('Add your content types');

where your_field_name is the name of the field calling the inline entity form

This usually needs pairing with overriding the "Save Node" button/link as well so again in the same hook_form_alter function we add

$form['field_your_field_name']['und']['form']['actions']['ief_add_save']['#value'] = t('Save your content type');

The produced form still has a title of "add new node" so this needs overriding as well, the code (in the same hook_form_alter does this

$form['field_your_field_name']['und']['form']['#title'] = t('Add your content type');

I have no need to, but a cursory look using devel page array revealed no way to override the resulting form field names etc (but I may be wrong over to someone else)

So to put this all together nicely

function helper_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'my_node_type_node_form':
      $form['field_your_field_name']['und']['actions']['ief_add']['#value'] = t('Add your content types');
      $form['field_your_field_name']['und']['form']['#title'] = t('Add your content type');
      $form['field_your_field_name']['und']['form']['actions']['ief_add_save']['#value'] = t('Add your content type');
      break;
  }
}

I hope that helps someone else using this module.

timwood’s picture

Thank you TechnoTim2010 and MXT for this public discussion and awesome example solution. It was just in time for what we needed!

Just to clarify one thing...the form you need to alter is the parent entity form, not each referenced node type's form. This was not obvious (at least to me) in the examples.

technotim2010’s picture

Tim

Yes the parent Entity form

Tim

(If only the middle text was palindromic this message would look really good)

demon326’s picture

I'm very sorry to bump this, i came across this post because its the exact same thing i need, but it won't work with me?

I have the following code in my custom module, named 'ashladan'

function ashladan_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'bands-node-form':
      $form['field_albums']['und']['actions']['ief_add']['#value'] = t('Add new albums');
      $form['field_albums']['und']['form']['#title'] = t('Add new album');
      $form['field_albums']['und']['form']['actions']['ief_add_save']['#value'] = t('Save album');
      break;
  }
} 

but it keeps using the node terms, instead of this?

timwood’s picture

demon326,
I think you need to use underscores not dashes in the "case" line. So:

function ashladan_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'bands_node_form':
      $form['field_albums']['und']['actions']['ief_add']['#value'] = t('Add new albums');
      $form['field_albums']['und']['form']['#title'] = t('Add new album');
      $form['field_albums']['und']['form']['actions']['ief_add_save']['#value'] = t('Save album');
      break;
  }
} 
demon326’s picture

Thank you Tim! I knew it had to be something simple, but i never thought it would be this simple!

rajab natshah’s picture

Thanks this worked ..
Hope to have this as an option in the Inline Entity Field widget.
To use the Title of the Field or custom text as 'Add new Node' , 'Save Node'.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

timwood’s picture

Sorry to revive this thread, but does anyone know how to identify the "Save node" button when editing a referenced node? The ID on the submit button is "edit-field-myfieldname-und-entities-0-form-actions-ief-edit-save". But I cannot figure out how to translate this to the field override inside my form_alter hook. This is using the IEF multiple widget.

Thanks!

technotim2010’s picture

Hi

Now I haven't tried this so apologies if it may be wrong and break, but taking my generic code earlier and changing "ief_add_save" to "ief_edit_save" should work then edit the label #value to whatever you require. (sorry have no access to the dev server with the dev site using IEF as at work)

so

?php
function helper_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'my_node_type_node_form':
      // insert other form alterations here
      $form['field_your_field_name']['und']['form']['actions']['ief_edit_save']['#value'] = t('Save your content type');
      break;
  }
}
?>
technotim2010’s picture

Hi

Now I haven't tried this so apologies if it may be wrong and break, but taking my generic code earlier and changing "ief_add_save" to "ief_edit_save" should work then edit the label #value to whatever you require. (sorry have no access to the dev server with the dev site using IEF as at work)

so

?php
function helper_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'my_node_type_node_form':
      // insert other form alterations here
      $form['field_your_field_name']['und']['form']['actions']['ief_edit_save']['#value'] = t('Save your content type');
      break;
  }
}
?>
timwood’s picture

Tim,
Thanks for the reply. That was the exact code I tried and it doesn't work. My co-worker did some investigating and came up with the code below that uses a different hook, which I'm going to test this morning. Here is what my co-worker (smoovb) suggested:

Looks like this is hard-coded into the ief module. Ief handles the inline 'edit' form with its own custom code, therefore, the normal drupal hooks do not apply. They do provide an internal hook with their module to alter the inline 'edit' form but it is fired before the buttons are added. To do this in the drupal way I added the following code:

function doc_ctype_announcement_inline​​_entity_form_entity_form_alte​r​(&$entity_form, &$form_state) {
  $entity_form['#pre_render'][]​ = 'doc_ctype_announcement_pre_r​e​nder';
}

function doc_ctype_announcement_pre_re​​nder($form) {
  $form['actions']['ief_edit_sa​ve']​['#value'] = t('Save @type', array('@type' => $form['#bundle']));
  return $form;
}
timwood’s picture

Some funny characters came through in that last code that appears when you copy/paste. Here is the code sans characters:

function doc_ctype_announcement_inline_entity_form_entity_form_alter(&$entity_form, &$form_state) {
  $entity_form['#pre_render'][] = 'doc_ctype_announcement_pre_render';
}

function doc_ctype_announcement_pre_render($form) {
  $form['actions']['ief_edit_save']['#value'] = t('Save @type', array('@type' => $form['#bundle']));
  return $form;
}
timwood’s picture

Yup. This worked. This code changes this particular form button, globally, for all entity types. Replaces @type, normally entity, with bundle. Not sure how this will affect a Drupal Commerce site or others using IEF to reference other entity types. Because it applies global, I added the code to a "helper" module.

operations’s picture

Thanks all! Very helpful..

apoc1’s picture

I didn't get that last one working. Should something been changed in the code of #17?

-enzo-’s picture

I did a variation for patch recommeded at #1880850-17: How to change the "node add $type" submit button text? to handle add and edit form

/**
 * Implements hook_inline_entity_form_entity_form_alter().
 */
function module_inline_entity_form_entity_form_alter(&$entity_form, &$form_state) {
  $entity_form['#pre_render'][] = 'open_politic_helper_pre_render';
}

function module_pre_render($form) {
  if(isset($form['actions']['ief_edit_save'])) {
    $form['actions']['ief_edit_save']['#value'] = t('Save @type', array('@type' => $form['#entity']->type));
  }
  else if(isset($form['actions']['ief_add_save'])) {
    $form['actions']['ief_add_save']['#value'] = t('Save @type', array('@type' => $form['#entity']->type));
  }

  return $form;
}
-enzo-’s picture

Issue summary: View changes

Missing }

sjhuskey’s picture

Issue summary: View changes

In case anyone is still struggling with this issue, I'd like to save you the time that I spent trying to implement the solutions above. There's a way to change the text of the submit button text in entity reference fields without having to write a module:

  1. Go to Structure>Content types and select the content type that has the entity reference field in it.
  2. Click "edit" on that field.
  3. Go to the box called "Inline Entity Form: Node"
  4. Click the checkbox "Override labels"
  5. Enter the text that you want to use to replace "node" and "nodes" in the "singular" and "plural" fields, respectively.
  6. Scroll down and click "submit" to save the change.
  7. Dance a happy little dance.
nicolas bouteille’s picture

That is EXACTLY what I was looking for...! I came here to actually suggest we would add such a feature... This module is AWESOME and sjhuskey thanks so much for the tip!
This made my day and I sure will dance about it right now :)

milos.kroulik’s picture

I can confirm, that tip in #21 works fine.

Karim EL Shazly’s picture

Thanks :) #22

ahoms’s picture

#22 is the right answer, there's no need for extra coding!

neighbors’s picture

Wow #22, that was awesome! I realize that was many years ago, but that nugget saved me a lot of digging/coding. Thanks again :)