Skip to main content
Drupal 8

Main navigation

  • Home
    • Question And Answer
    • NEWS
    • Projects
  • Tutorials - Drupal
    • Android
    • Other
User account menu
  • Log in

Breadcrumb

  1. Home

Preprocess a Field, Change Theming of a field

By editor , 29 July, 2016
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;
}

 

Tags

  • Drupal 8
  • Drupal 7
  • Theming
  • Pre Process
Change the states of an element based on another element (field)

Comments

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.

Links

  • Drupal.org
  • Drupal core release cycle
  • Drupal events with ease
  • Unit test with Drupal using PHPUnit (Drupal 10)
  • Tokens for file upload url
  • Tips for Docker
  • CKEditor inline image files usage for custom forms.
  • Install Docker on Linux Mint
  • Install PHP 8.1
  • Drupal Security Best Practices
  • Order and sort items with tabledrag
  • Add a custom service YAML container
  • Apply a patch with composer