Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I have created new form components using '#type' => 'multiselect'.
Here I need to change the labels Available options, Selected options to some other text.
How can we do it through custom code. Can anyone suggest me.
Comment | File | Size | Author |
---|---|---|---|
#4 | multiselect-alter_labels_for_options-2242949-4.patch | 1.6 KB | stefanos.petrakis@gmail.com |
Comments
Comment #1
attheshow CreditAttribution: attheshow commentedYou might want to take a look here. These are some good easy methods I've seen used before for something like this: https://drupal.org/node/522036
Comment #2
rameshbabu.g CreditAttribution: rameshbabu.g commentedThanks for your quick response. I already tried String Overrides module in local and it is working fine.
Your pasted link contains 2 methods. So method 1 is more sufficient to me because it is a quick method for small number of strings.
$conf['locale_custom_strings_en'][''] = array(
'Available options' => 'Available Groups',
'Selected options' => 'Assigned Groups',
);
But here I am using '#type' => 'multiselect' in multiple forms. So I need different labels in different places. Is there any way to change strings conditionally.
Comment #3
attheshow CreditAttribution: attheshow commentedYou could try using hook_form_alter() in a custom module.
Comment #4
stefanos.petrakis@gmail.comThis was an issue for us, we solved this using this patch, that offers the following two options to FAPI array:
'#available_options_label' => t('Custom label for options'),
'#selected_options_label' => t('Custom label for selected items'),
Thanks for reviewing this!
Comment #5
stefanos.petrakis@gmail.com