function finder_form in Finder 7.2
Same name and namespace in other branches
- 6 includes/finder.form.inc \finder_form()
- 7 includes/finder.form.inc \finder_form()
FAPI definition for the finder form.
Parameters
&$form: The Forms API form array.
&$form_state: The Forms API form state.
$finder: The finder object.
See also
1 string reference to 'finder_form'
- finder_forms in ./
finder.module - Implements hook_forms().
File
- includes/
form.inc, line 19 - The finder form.
Code
function finder_form($form, &$form_state, $finder) {
global $user;
ctools_include('plugins');
// Make sure drupal core loads this file when handling this form.
form_load_include($form_state, 'inc', 'finder', 'includes/form');
$form_state['finder'] = $finder;
// see if there is already a form state we should be using.
$finder_form_state = finder_form_state($finder);
if (is_array($finder_form_state)) {
$form_state = array_merge($form_state, $finder_form_state);
}
$finder->form_state = $form_state;
module_invoke_all('finder_form', $finder);
$form['finder_name'] = array(
'#type' => 'value',
'#value' => $finder->name,
);
$form['#action'] = url($finder->path);
if ($user->uid) {
$form['#token'] = FALSE;
}
$form['finder_form'] = array(
'#weight' => 0,
'#prefix' => '<div class="finder-form finder-' . $finder->name . '">',
'#suffix' => '</div>',
);
$header = $finder
->setting('header');
if (!empty($header['value']) && isset($header['format'])) {
$form['finder_form']['#prefix'] .= '<div class="prefix">' . check_markup($header['value'], $header['format'], FALSE) . '</div>';
}
$max_weight = 0;
$rendered_elements = array();
$ajax_settings = array();
foreach ($finder->elements as $element) {
// Ensure the module plugin file is always loaded.
if (isset($element->element_handler['file'])) {
$file = $element->element_handler['file'];
if (isset($element->element_handler['path'])) {
$file = $element->element_handler['path'] . '/' . $file;
}
$pathinfo = pathinfo($file);
form_load_include($form_state, $pathinfo['extension'], $element->element_handler['plugin module'], str_replace(drupal_get_path('module', $element->element_handler['plugin module']) . '/', '', $pathinfo['dirname']) . '/' . $pathinfo['filename']);
}
// Skip element callback - decide whether to render this element now.
if (!empty($element->parent) && !in_array($element->parent, $rendered_elements)) {
continue;
}
if ($handler_function = ctools_plugin_get_function($element->element_handler, 'skip element callback')) {
$skip_element_result = $handler_function($element, $form_state);
if ($skip_element_result) {
continue;
}
}
// Register this element to signify that it is being rendered.
$rendered_elements[] = $element->id;
$max_weight = max($max_weight, $element->weight);
if ($finder
->esetting($element, 'reduce')) {
$ajax_settings['reduce'][$element->id] = $finder
->esetting($element, 'reduce');
}
if ($finder
->esetting($element, 'ajax_load')) {
$form_element = array(
'#markup' => '<div class="finder-form-element finder-form-element-' . $element->id . '"></div>',
);
$ajax_settings['load'][] = $element->id;
}
else {
$form_element = finder_form_element($finder, $element, $form_state);
}
$parents = array_reverse($finder
->element_parents($element));
$value =& $form['finder_form'];
foreach ($parents as $p) {
$value =& $value[$p];
}
$value[$element->id] = $form_element;
}
if ($finder
->setting('autosubmit')) {
$ajax_settings['autosubmit'][] = $finder->build_id;
}
if (!empty($form_state['finished']) && $finder
->setting('ajax_results_load')) {
$ajax_settings['results_load'][] = $finder->build_id;
}
if ($finder
->setting('ajax_results_update')) {
$ajax_settings['results_update'][] = $finder->build_id;
}
if (!empty($ajax_settings)) {
drupal_add_js(array(
'finder' => array(
$finder->name => $ajax_settings,
),
), 'setting');
drupal_add_js(drupal_get_path('module', 'finder') . '/finder.js');
}
// Skip empty.
$form['finder_form'] = finder_form_skip_empty($form['finder_form'], $finder);
$form['finder_form']['actions']['#weight'] = $max_weight + 100;
if ($finder
->setting('find_button')) {
$form['finder_form']['actions']['find'] = array(
'#type' => 'submit',
'#name' => 'find',
'#value' => $finder
->setting('find_text'),
);
if ($finder
->setting('ajax')) {
$wrapper = $finder->build_id;
$form_state['ajax_display'] = 'block';
// Check if the 'ajax_remote' setting is on, that we are on the finder page, and that we are in a block.
if ($finder
->setting('ajax_remote') && strpos($_GET['q'], $finder->path) === 0 && $finder->build_display === 'block') {
// We are using the block as a remote control for the page. Change the wrapper for Ajax purposes.
$wrapper = 'finder-page-' . $finder->name . '-wrapper';
$form_state['ajax_display'] = 'page';
}
$form['finder_form']['actions']['find']['#ajax'] = array(
'callback' => 'finder_ajax',
'wrapper' => $wrapper,
'method' => 'replace',
'effect' => $finder
->setting('ajax_effect'),
);
}
}
if ($finder
->setting('go_button')) {
$form['finder_form']['actions']['go'] = array(
'#type' => 'submit',
'#name' => 'go',
'#value' => $finder
->setting('go_text'),
);
}
$footer = $finder
->setting('footer');
if (!empty($footer['value']) && isset($footer['format'])) {
$form['finder_form']['#suffix'] = '<div class="suffix">' . check_markup($footer['value'], $footer['format'], FALSE) . '</div>' . $form['finder_form']['#suffix'];
}
$form['#submit'] = array(
'finder_form_submit',
);
$form['#validate'] = array(
'finder_form_validate',
);
return $form;
}