1

This doesn't seem to be the kind of thing you can change using hook_form_alter() unless I'm missing something.

The label of the "From" field can be any value you want, but the "to" field, if you have one, defaults to "to", see modules/date/date_elements.inc, line 369:

    $element[$to_field]['#title'] = t('to:');

so what's the correct way to change that to a value of my choosing, i.e. "Expires"? Via the Theme?

3

If you look further on down in date_elements.inc at line 412 you'll notice:

drupal_alter('date_combo_process', $element, $form_state, $context);

which allows any module to alter what it's created, eg, something like this:

function YOURMODULE_date_combo_process_alter(&$element, &$form_state, &$context) {

  $element['value2']['#title'] = t('expires:'); // this will change that to: to expires:

}

Just realize this simple example will do this for every instance of a combination to/from date, but information to get more specific is contained in $element, $form_state and $context. For example, the specific field name is contained in $element['#field_name'] and the form_id is in $form_state['build_info']['form_id'].

| improve this answer | |
  • Thank you. That worked perfectly. Just for the record, is it unusual for the Date module's forms to work this way? Providing their own method of changing the module's forms because it's not accessible via form_alter ? – John Horner Jan 27 '14 at 22:12
  • They are both alters, eg, MODULE_TYPE_alter(), so MODULE_form_alter() and MODULE_date_combo_process_alter() both allow modules to alter something another module has created, eg, the date and form modules. In this case, they are just nested, so you need to alter the piece created by the right module. BTW, @xurshid29's answer below works as well; just another example of how extensible and in many ways Drupal is. – Jimajamma Jan 27 '14 at 22:25
1

I always do this kind of thing with hook_form_alter() and pre_render function: example:

function MY_MODULE_OR_THEME_form_alter(&$form, &$form_state, $form_id) {
  if($form_id == 'MY_FORM_ID') {
   $form['#pre_render'][] = 'MY_CUSTOM_pre_render';
  }
}

function MY_CUSTOM_pre_render($element) {
  //dpm($form);
  //$element['MY_FIELD_NAME']['max']['#title'] = t('MY NEW TITLE'); // Find your proper field element.
  return $element;
}
| improve this answer | |
0

There is a module named String Overrides that lets you override any string that is inserted via the t() function. You should be able to use that to module override "to:".

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.