protected function views_plugin_style_geojson::form_fields_replace in Views GeoJSON 7
Replaces form field placehoders with their substitutions.
Parameters
string $output: The text output of the current display.
bool $encode: Whether or not to json encode placeholders.
Return value
string Returns the output of the current display with form field placeholders replaced.
See also
template_preprocess_views_view()
1 call to views_plugin_style_geojson::form_fields_replace()
- views_plugin_style_geojson::render in views/
views_plugin_style_geojson.inc - Implementation of view_style_plugin::render().
File
- views/
views_plugin_style_geojson.inc, line 415 - Views style plugin to render nodes in the GeoJSON format.
Class
- views_plugin_style_geojson
- Implementation of views_plugin_style.
Code
protected function form_fields_replace($output, $encode = TRUE) {
// If form fields were found in the view.
if (views_view_has_form_elements($this->view)) {
// The minimum form elements needed to do the replacement are 'output',
// '#substitutions' and the form element name of each field.
$elements = array(
'output',
'#substitutions',
);
foreach ($this->view->field as $field_name => $field) {
$form_element_name = $field_name;
if (method_exists($field, 'form_element_name')) {
$form_element_name = $field
->form_element_name();
}
$elements[] = $form_element_name;
}
// Wrap the output in a views form.
$form = drupal_get_form(views_form_id($this->view), $this->view, $output);
// Remove all but the necessary form elements.
$form = array_intersect_key($form, array_flip($elements));
if ($encode) {
// JSON encode placeholders and fields for output in feeds.
foreach ($form['#substitutions']['#value'] as &$substitution) {
$field_name = $substitution['field_name'];
$row_id = $substitution['row_id'];
// If the field exists for the row.
if (isset($form[$field_name][$row_id])) {
// Render and json encode the the field for the row.
$form[$field_name][$row_id] = array(
'#markup' => trim(drupal_json_encode(drupal_render($form[$field_name][$row_id])), '"'),
);
}
$substitution['placeholder'] = trim(drupal_json_encode($substitution['placeholder']), '"');
}
}
// Perform the replacement.
$output = theme('views_form_views_form', array(
'form' => $form,
));
}
return $output;
}