function ViewsFormMainForm::preRenderViewsForm
Same name in other branches
- 9 core/modules/views/src/Form/ViewsFormMainForm.php \Drupal\views\Form\ViewsFormMainForm::preRenderViewsForm()
- 8.9.x core/modules/views/src/Form/ViewsFormMainForm.php \Drupal\views\Form\ViewsFormMainForm::preRenderViewsForm()
- 11.x core/modules/views/src/Form/ViewsFormMainForm.php \Drupal\views\Form\ViewsFormMainForm::preRenderViewsForm()
Replaces views substitution placeholders.
Parameters
array $element: An associative array containing the properties of the element. Properties used: #substitutions, #children.
Return value
array The $element with prepared variables ready for #theme 'form' in views_form_views_form.
1 call to ViewsFormMainForm::preRenderViewsForm()
- ViewsHooksTest::testViewsFormMainFormPreRender in core/
modules/ views/ tests/ src/ Kernel/ ViewsHooksTest.php - Tests how hook_views_form_substitutions() makes substitutions.
File
-
core/
modules/ views/ src/ Form/ ViewsFormMainForm.php, line 37
Class
Namespace
Drupal\views\FormCode
public static function preRenderViewsForm(array $element) {
// Placeholders and their substitutions (usually rendered form elements).
$search = [];
$replace = [];
// 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::service('renderer')->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[] = Html::escape($placeholder);
// Ensure that any replacements made are safe to make.
if (!$substitution instanceof MarkupInterface) {
$substitution = Html::escape($substitution);
}
$replace[] = $substitution;
}
// Apply substitutions to the rendered output.
$output = str_replace($search, $replace, \Drupal::service('renderer')->render($element['output']));
$element['output'] = [
'#markup' => ViewsRenderPipelineMarkup::create($output),
];
return $element;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.