function views_pre_render_views_form_views_form in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/views/views.module \views_pre_render_views_form_views_form()
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 views_pre_render_views_form_views_form()
- ViewsHooksTest::testViewsPreRenderViewsFormViewsForm in core/
modules/ views/ src/ Tests/ ViewsHooksTest.php - Tests how hook_views_form_substitutions() makes substitutions.
1 string reference to 'views_pre_render_views_form_views_form'
- ViewsFormMainForm::buildForm in core/
modules/ views/ src/ Form/ ViewsFormMainForm.php - Form constructor.
File
- core/
modules/ views/ views.module, line 610 - Primarily Drupal hooks and global API functions to manipulate views.
Code
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[] = Html::escape($placeholder);
// Ensure that any replacements made are safe to make.
if (!SafeMarkup::isSafe($substitution)) {
$substitution = Html::escape($substitution);
}
$replace[] = $substitution;
}
// Apply substitutions to the rendered output.
$output = str_replace($search, $replace, drupal_render($element['output']));
$element['output'] = [
'#markup' => ViewsRenderPipelineMarkup::create($output),
];
return $element;
}