hook_form_alter for views exposed filter form


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /**
  2.  * Implementation of hook_form_FORM_ID_alter() for 'views exposed form'
  3.  * Change the first option label '<All>' to 'Filter by Identifier Name' for exposed filters
  4.  * The filter identifier needs set up with underscores for multiple word filter names
  5.  * e.g. 'document_type' becomes 'Document Type'
  6.  */
  7.  
  8. function mymodule_form_views_exposed_form_alter (&$form, $form_state) {
  9. foreach($form as $key => &$value) {
  10. if(isset($value['#options']['All'])) {
  11. $label = ucwords(strtolower(str_replace('_', ' ', $key)));
  12. $value['#options']['All'] = t('Filter by !label', array('!label' => $label));
  13. }
  14. }
  15. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.