function views_pre_render_views_form_views_form

views_pre_render_views_form_views_form($element)

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.

File

core/modules/views/views.module, line 606
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 (!($substitution instanceof MarkupInterface)) {
      $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;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!views!views.module/function/views_pre_render_views_form_views_form/8.1.x