diff --git a/theme/theme.inc b/theme/theme.inc index bf772b2..78d0755 100644 --- a/theme/theme.inc +++ b/theme/theme.inc @@ -873,7 +873,7 @@ function template_preprocess_views_exposed_form(&$vars) { */ function theme_views_form_views_form($variables) { $form = $variables['form']; - $view = $form['view']['#value']; + $view = $form['#view']->view; // Placeholders and their substitutions (usually rendered form elements). $search = array(); diff --git a/views.module b/views.module index b77a67d..a01daf1 100644 --- a/views.module +++ b/views.module @@ -1475,6 +1475,15 @@ function vpr_trace() { // Views form (View with form elements) /** + * A special purpose object harbouring values that cannot be serialized. + */ +class ViewsFormShield { + function __sleep() { + return array(); + } +} + +/** * This is the entry function. Just gets the form for the current step. * The form is always assumed to be multistep, even if it has only one * step (the default 'views_form_vews_form' step). That way it is actually @@ -1486,12 +1495,8 @@ function views_form($form, &$form_state, $view, $output) { $form = array(); $form['#validate'] = array('views_form_validate'); $form['#submit'] = array('views_form_submit'); - // The view is stored in $form and not $form_state because - // the theme functions only get $form. - $form['view'] = array( - '#type' => 'value', - '#value' => $view, - ); + $form['#process'][] = '_views_form_process'; + // Tell the preprocessor whether it should hide the header, footer, pager... $form['show_view_elements'] = array( '#type' => 'value', @@ -1503,6 +1508,22 @@ function views_form($form, &$form_state, $view, $output) { } /** + * #process function for Views Form. + * + * This is called after the initial form has been generated and before + * cached forms are processed. + */ +function _views_form_process(&$element, $form_state, $form) { + // The view is stored here in $form because the theme functions only get $form. + // We don't want it to be serialized, so we wrap it into a shield. + // This is ONLY for the usage of theme functions. For validate and submit + // functions, use $form_state['build_info']['args'][0] directly. + $element['#view'] = new ViewsFormShield(); + $element['#view']->view = $form_state['build_info']['args'][0]; + return $element; +} + +/** * The basic form validate handler. * Fires the hook_views_form_validate() function. */ @@ -1580,7 +1601,7 @@ function views_form_views_form($form, &$form_state, $view, $output) { * on the views fields. */ function views_form_views_form_validate($form, &$form_state) { - $view = $form['view']['#value']; + $view = $form_state['build_info']['args'][0]; // Call the validation method on every field handler that has it. foreach ($view->field as $field_name => $field) { @@ -1596,7 +1617,7 @@ function views_form_views_form_validate($form, &$form_state) { * on the views fields. */ function views_form_views_form_submit($form, &$form_state) { - $view = $form['view']['#value']; + $view = $form_state['build_info']['args'][0]; // Call the submit method on every field handler that has it. foreach ($view->field as $field_name => $field) {