You are here

function theme_views_form_views_form in Views (for Drupal 7) 8.3

Same name and namespace in other branches
  1. 6.3 theme/theme.inc \theme_views_form_views_form()
  2. 7.3 theme/theme.inc \theme_views_form_views_form()

Theme function for a View with form elements: replace the placeholders.

File

theme/theme.inc, line 1016
Preprocessors and helper functions to make theming easier.

Code

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 = module_invoke_all('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);
}