Commit b1624c56 authored by webchick's avatar webchick

Issue #1912600 by joelpittet, bzitzow, dawehner: Remove...

Issue #1912600 by joelpittet, bzitzow, dawehner: Remove theme_views_form_views_form() in favour of a prerender callback.
parent 64171682
......@@ -1171,7 +1171,8 @@ function views_form($form, &$form_state, ViewExecutable $view, $output) {
function views_form_views_form($form, &$form_state, ViewExecutable $view, $output) {
$form['#prefix'] = '<div class="views-form">';
$form['#suffix'] = '</div>';
$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';
......@@ -1301,6 +1302,44 @@ 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, #children.
* @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) {
// Placeholders and their substitutions (usually rendered form elements).
$search = array();
$replace = array();
// Add in substitutions provided by the form.
foreach ($element['#substitutions']['#value'] as $substitution) {
$field_name = $substitution['field_name'];
$row_id = $substitution['row_id'];
$search[] = $substitution['placeholder'];
$replace[] = isset($element[$field_name][$row_id]) ? drupal_render($element[$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.
$element['output']['#markup'] = str_replace($search, $replace, $element['output']['#markup']);
// Render and add remaining form fields.
$element['#children'] = drupal_render_children($element);
return $element;
}
/**
* Form builder for the exposed widgets form.
*
......
......@@ -1070,38 +1070,6 @@ function template_preprocess_views_exposed_form(&$variables) {
}
}
/**
* Theme function for a View with form elements: replace the placeholders.
*/
function theme_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.
return drupal_render_children($form);
}
/**
* Theme function for the Mini pager.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment