Change the label on the button

Can I write something else to the button that says add items?

1 Like

Hey @compact2, it might be easiest to change the “Add items” string by implementing hook_form_FORM_ID_alter. I believe this is the Log form you are looking at, so your function name would be mymodule_form_log_form_alter.

I’ve also been curious about using translations for cases like this. Rather than translating to a different language you can use the same system to just change the string that is used in your current language. (I know this is possible in drupal 9, but not as familiar with translations in drupal 7!)

That said, I don’t think this is your best option here. Since “Add items” is likely used in many places you would need to be careful - translating to “Add more” might be OK, but translating to “Add assets” would be problematic in other contexts.

1 Like

I have such a code. What do I have to add to change that green button alone?

<?php function field_job_list_label_field_widget_form_alter(&$element, &$form_state, $context) { // first check the type of the field to ensure only change the required widget if ($context['field']['field_name'] == 'field_jobs_list') { $element['#title'] = t('Create account'); } }

what is the type of green button?

It will be easiest if you can walk through the code with a debugger. I don’t have that setup at the moment though so I can’t get the exact answer for you…

Looks like this might be a good example as well:

I’m pretty sure you’ll want to change the #value key of the button, not the #title key. This is what they do in the example above.

My best guess is it might be $form['field_farm_asset']['und']['add_more']['#value'] = "New text";