I create my own hooks module, in a simple frame (to test it) to change in exposed filter of view to 'All' , but when I enable this module, it's work fine but make my site slow .. and just when I disable it , my site back to fast, what is my mistake?


name = my hooks module
description = hooks website module.
package = myhooks
core = 7.x


function myhooks_form_views_exposed_form_alter(&$form, $form_state, $form_id) {
  if($form_id == 'views_exposed_form') { 
    $form['name_list']['#options']['All'] = 'All';
  • 1
    Can't see any reason why this would slow things down, but you should pass &$form_state by reference, so the parameters are: (&$form, &$form_state, $form_id)
    – Ollie
    Commented May 4, 2014 at 13:15
  • If you use hook_form_FORM_ID_alter you shouldn't need to test form id again. Not against the same value, anyway. Shouldn't slow down things, but anyway.
    – Mołot
    Commented May 4, 2014 at 13:56
  • I'm already used hook_form_FORM_ID_alter function, and I using FORM_ID = 'views_exposed_form' .. and yes I think I don't need to test form_id .. I will remove it .. thank you
    – Tasneem
    Commented May 4, 2014 at 20:51

3 Answers 3


I see two possible reasons:

  1. You pass form state by value. It should be passed by reference. It is a really, really big array, so copying it when there is no need to may eat up quite a lot of memory, slowing down everything.

  2. You alter $form['name_list']['#options'] in all views exposed forms. But probably most of these forms does not have name_list element at all. So what you do can generate array items that are bad from form api point of view, slowing down form processing, and generate warnings. Server will not show you warnings, but it will save them to error logs, and writing to disk is slow.


I think the reason for the site becoming slow is the $form_id.

views_exposed_form is the $form_id of all the exposed forms, and will get applied to all the views with exposed filters. You could try filtering the exact view by something like $form['#id'].

Also, if you implement hook_form_FORM_ID_alter, you don't have to check the $form_id again inside the hook implementation.

  • 1
    All totally correct, but why would a simple string comparison slow the whole site down?
    – Clive
    Commented May 4, 2014 at 13:36
  • @Clive I couldn't think of any other reason. I would think if views is used heavily on the site, and as OP mentioned about the tests performed with this module, I would suspect this might be the reason.
    – AjitS
    Commented May 4, 2014 at 13:45
  • I'm already used hook_form_FORM_ID_alter function, and I using FORM_ID = 'views_exposed_form' because my view has multi blocks, and I try to put main view ID, but it dose not work .. how can I specify view id and block id in this function ?
    – Tasneem
    Commented May 4, 2014 at 20:47

$form['name_list']['#options']['All'] = 'All'; -> That return all result on the page .So loading process is very slow. If You need to fast the page that if you will check "options[expose][required]" the check box .if exposed filter is not taken a empty or null value due to loading page .when enter the value that return all page.

Reference : https://drupal.org/node/138374

  • so how can I determine view id? can I do something like $form['view_id']['block_id']['name_list']['#options']['All'] = 'All'; and where can I find that check box option options[expose][required] ?
    – Tasneem
    Commented May 5, 2014 at 9:24
  • better you will do this process is in admin configuation using view modules. In view Fliter criteria -> Configure filter criterion: -> Expose this filter to visitors, to allow them to change it -> Filter type to expose -> Required Commented May 5, 2014 at 10:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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