How to change the text of "Add more values" button? I don't want to change the text from modules/cck/modules/content_multigroup/content_multigroup.node_form.inc.

I tried to print $form array in hook_form_alter() but can't find "Add more values" but the only thing similar that I see is "Add another item".

Comments

andreiashu’s picture

markus_petrux’s picture

Status: Active » Fixed
xn2001’s picture

thx both of you (andreiashu and markus_petrux)!

Status: Fixed » Closed (fixed)

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

agileware’s picture

Title: How to change the text of "Add more values" button? » Make "Add more values" button text themeable?
Category: support » feature
Status: Closed (fixed) » Needs review
StatusFileSize
new1.86 KB

Here is a patch that makes the button text themeable which would make the process much easier
seeing as you can't just form_alter it in the usual manner.

interestingaftermath’s picture

Status: Needs review » Active

Where do you theme this text?

agileware’s picture

Status: Active » Needs review

You can either do it in the manner suggested in #2, which is fairly complex just to theme some text on a button
OR
you apply the patch in #5 and then in your theme put this code in your template.php file

<?php

/**
 * Theme the label for the "Add more values" button
 */
function YOURTHEMENAME_content_multigroup_add_more_label($group_name) {
  return t('Add more values');
}

?>

Then you just change the 'Add more values' part of that code snippet to be whatever text you want on the button.

interestingaftermath’s picture

Thanks!

Any help you could be on http://drupal.org/node/156860 would be greatly appreciated. I really need that functionality and it looks like it's working for others.

karens’s picture

Status: Needs review » Fixed

Patch applied. I agree this makes more sense.

tomsm’s picture

I want to change "Add more values" only for one multigroup field named "group_order_line". I added the following to my template.php:

function acquia_marina_content_multigroup_add_more_label($group_order_line) {
return t('Add more products');

The "Add more values" of other multigroup fields also changes.
How can I limit the change to one field or one content type?

I use Content Construction Kit (CCK) 6.x-3.0-alpha3

agileware’s picture

The $group_name parameter of the theme function is the name of the group currently being themed,
so to just do that particular group you could do:

<?php
/**
 * Theme the label for the "Add more values" button
 */
function acquia_marina_content_multigroup_add_more_label($group_name) {
  // For the group_order_line group.
  if ($group_name == 'group_order_line') {
    return t('Add more products');
  }
  // For all other groups.
  return t('Add more values');
}
?>

To do it for a particular content type you could do (or you could use the solution in #2):

<?php
/**
 * Theme the label for the "Add more values" button
 */
function acquia_marina_content_multigroup_add_more_label($group_name) {
  // For the page node type add page.
  if (arg(0) == 'node' && arg(1) == 'add' && arg(2) == 'page') {
    return t('Add more products');
  }
  // For the page node type edit page.
  else if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'edit') {
    $node = node_load(arg(1));
    if (!empty($node) && $node->type == 'page') {
      return t('Add more products');
    }
  }
  // Otherwise.
  return t('Add more values');
}
?>

You can also add the group name check from the first example in the second example to just do a single group from particular content type.

karens’s picture

Might be nice to pass the $node to the theme as well as the group name, as a second argument. If someone wants to make a patch for that we can make that change.

agileware’s picture

Status: Fixed » Active

Yeah, I was thinking that when I started having to do node loads in the template.php example above.

Will do when I get some time.

tomsm’s picture

@Agileware
Thank you! #11 works great.

agileware’s picture

Status: Active » Needs review
StatusFileSize
new1.73 KB

Here is a patch to pass the node into the theme function for easier themeing.

ezra-g’s picture

Fwiw, this can be form_altered by targeting, for example, with a "field_presenters" user-reference field:

$form['field_presenters']['field_presenters_add_more']['#value'] = t('Add another presenter');

I'm not sure whether or not that satisfies the need provided by this patch.

ezra-g’s picture

After further thought, if we had a theme function to change every button's value/label, we'd have a ton of theme functions. hook_form_alter() is effectual here, and I think that eliminates the need for this patch.

agileware’s picture

@ezra-g:
Also note that this issue is regarding the add more button for a CCK 3 multigroup, not just a single field's add more button.