function views_form_views_form in Views (for Drupal 7) 7.3
Same name and namespace in other branches
- 8.3 views.module \views_form_views_form()
- 6.3 views.module \views_form_views_form()
Callback for the main step of a Views form.
Invoked by views_form().
1 string reference to 'views_form_views_form'
- views_form in ./
views.module - This is the entry function. Just gets the form for the current step.
File
- ./
views.module, line 1967 - Primarily Drupal hooks and global API functions to manipulate views.
Code
function views_form_views_form($form, &$form_state, $view, $output) {
$form['#prefix'] = '<div class="views-form">';
$form['#suffix'] = '</div>';
$form['#theme'] = 'views_form_views_form';
$form['#validate'][] = 'views_form_views_form_validate';
$form['#submit'][] = 'views_form_views_form_submit';
// Add the output markup to the form array so that it's included when the form
// array is passed to the theme function.
$form['output'] = array(
'#type' => 'markup',
'#markup' => $output,
// This way any additional form elements will go before the view
// (below the exposed widgets).
'#weight' => 50,
);
$substitutions = array();
foreach ($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();
}
$method_form_element_row_id_exists = FALSE;
if (method_exists($field, 'form_element_row_id')) {
$method_form_element_row_id_exists = TRUE;
}
// If the field provides a views form, allow it to modify the $form array.
$has_form = FALSE;
if (property_exists($field, 'views_form_callback')) {
$callback = $field->views_form_callback;
$callback($view, $field, $form, $form_state);
$has_form = TRUE;
}
elseif (method_exists($field, 'views_form')) {
$field
->views_form($form, $form_state);
$has_form = TRUE;
}
// Build the substitutions array for use in the theme function.
if ($has_form) {
foreach ($view->result as $row_id => $row) {
if ($method_form_element_row_id_exists) {
$form_element_row_id = $field
->form_element_row_id($row_id);
}
else {
$form_element_row_id = $row_id;
}
$substitutions[] = array(
'placeholder' => '<!--form-item-' . $form_element_name . '--' . $form_element_row_id . '-->',
'field_name' => $form_element_name,
'row_id' => $form_element_row_id,
);
}
}
}
// Give the area handlers a chance to extend the form.
$area_handlers = array_merge(array_values($view->header), array_values($view->footer));
$empty = empty($view->result);
foreach ($area_handlers as $area) {
if (method_exists($area, 'views_form') && !$area
->views_form_empty($empty)) {
$area
->views_form($form, $form_state);
}
}
$form['#substitutions'] = array(
'#type' => 'value',
'#value' => $substitutions,
);
$form['actions'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array(
'form-actions',
),
),
'#weight' => 100,
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}