commit 6f0ff4a61d232e5cb22241661cb82b83532d99ca Author: Joel Pittet Date: Sun Apr 7 21:33:17 2013 -0700 pre_render first attempt diff --git a/core/modules/views/templates/views-form-views-form.html.twig b/core/modules/views/templates/views-form-views-form.html.twig deleted file mode 100644 index 6edbeb8..0000000 --- a/core/modules/views/templates/views-form-views-form.html.twig +++ /dev/null @@ -1,15 +0,0 @@ -{# -/** -* @file -* Default theme implementation to display form children. -* -* Available variables: -* - children: Form child elements. -* -* @see template_preprocess() -* @see template_preprocess_views_form_views_form() -* -* @ingroup themeable -*/ -#} -{{ children }} diff --git a/core/modules/views/views.module b/core/modules/views/views.module index 39ad43b..3a740c1 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -159,7 +159,6 @@ function views_theme($existing, $type, $theme, $path) { $hooks['views_form_views_form'] = $base + array( 'render element' => 'form', - 'template' => 'views-form-views-form', ); $hooks['views_exposed_form'] = $base + array( @@ -1272,7 +1271,8 @@ function views_form($form, &$form_state, ViewExecutable $view, $output) { function views_form_views_form($form, &$form_state, ViewExecutable $view, $output) { $form['#prefix'] = '
'; $form['#suffix'] = '
'; - $form['#theme'] = 'views_form_views_form'; + $form['#theme'] = 'form'; + $form['#pre_render'][] = 'views_pre_render_views_form_views_form'; $form['#validate'][] = 'views_form_views_form_validate'; $form['#submit'][] = 'views_form_views_form_submit'; @@ -1404,6 +1404,45 @@ function views_form_views_form_submit($form, &$form_state) { } /** + * Replaces views substitution placeholders. + * + * @param array $element + * An associative array containing the properties of the element. + * Properties used: #substitutions, @todo. + * @return array + * The $element with prepared variables ready for #theme 'form' in views_form_views_form. + */ +function views_pre_render_views_form_views_form($element) { + $form = $element['form']; + + // Placeholders and their substitutions (usually rendered form elements). + $search = array(); + $replace = array(); + + // Add in substitutions provided by the form. + foreach ($form['#substitutions']['#value'] as $substitution) { + $field_name = $substitution['field_name']; + $row_id = $substitution['row_id']; + + $search[] = $substitution['placeholder']; + $replace[] = isset($form[$field_name][$row_id]) ? drupal_render($form[$field_name][$row_id]) : ''; + } + // Add in substitutions from hook_views_form_substitutions(). + $substitutions = Drupal::moduleHandler()->invokeAll('views_form_substitutions'); + foreach ($substitutions as $placeholder => $substitution) { + $search[] = $placeholder; + $replace[] = $substitution; + } + + // Apply substitutions to the rendered output. + $form['output']['#markup'] = str_replace($search, $replace, $form['output']['#markup']); + + // Render and add remaining form fields. + $element['#children'] = drupal_render_children($form); + return $element; +} + +/** * Form builder for the exposed widgets form. * * Be sure that $view and $display are references. diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc index 6eb5ff7..8474b13 100644 --- a/core/modules/views/views.theme.inc +++ b/core/modules/views/views.theme.inc @@ -1004,45 +1004,6 @@ function template_preprocess_views_exposed_form(&$vars) { $vars['button'] = drupal_render_children($form); } -/** - * Prepares variables for views form views form. - * - * Default template: views-form-views-form.html.twig. - * - * @param array $variables - * An associative array containing: - * - children: Stores the form children as rendered by drupal_render_children() - * - form: A dependency that the form children are derived from - */ -function template_preprocess_views_form_views_form(&$variables) { - $form = $variables['form']; - - // Placeholders and their substitutions (usually rendered form elements). - $search = array(); - $replace = array(); - - // Add in substitutions provided by the form. - foreach ($form['#substitutions']['#value'] as $substitution) { - $field_name = $substitution['field_name']; - $row_id = $substitution['row_id']; - - $search[] = $substitution['placeholder']; - $replace[] = isset($form[$field_name][$row_id]) ? drupal_render($form[$field_name][$row_id]) : ''; - } - // Add in substitutions from hook_views_form_substitutions(). - $substitutions = Drupal::moduleHandler()->invokeAll('views_form_substitutions'); - foreach ($substitutions as $placeholder => $substitution) { - $search[] = $placeholder; - $replace[] = $substitution; - } - - // Apply substitutions to the rendered output. - $form['output']['#markup'] = str_replace($search, $replace, $form['output']['#markup']); - - // Render and add remaining form fields. - $variables['children'] = drupal_render_children($form); -} - function theme_views_mini_pager($vars) { global $pager_page_array, $pager_total;