Preprocess a Field, Change Theming of a field

Submitted by editor on Fri, 07/29/2016 - 17:13
Question

How to remove the default date format option added by date module ?
How to Change the Title, Change the description ("E.g., 29/07/2016") of the date widget ?

For thah you must use an additional process.

1. Create a custom module (Example : Here we use mymodule)

2. in the mymodule.module, add the hook hook_alter_element_info_alter and create a function '_mymodule_date_popup_process_alter'

Ex:

/**
 * implements hook_element_info_alter()
 *
 */
function mymodule_alter_element_info_alter(&$type) {
  if (isset($type['date_popup'])) {
    $type['date_popup']['#process'][] = '_mymodule_date_popup_process_alter';
  }
}
function _mymodule_date_popup_process_alter(&$element, &$form_state, $context) {
  unset($element['date']['#description']);
  if ($element['#name'] == 'node_changed') {
    $element['date']['#title'] = "The Date is";
  }
  return $element;
}

 

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.