You are here

function ctools_search_form_content_type_render in Chaos Tool Suite (ctools) 6

Same name and namespace in other branches
  1. 7 plugins/content_types/search/search_form.inc \ctools_search_form_content_type_render()

Render the custom content type.

File

plugins/content_types/search/search_form.inc, line 29

Code

function ctools_search_form_content_type_render($subtype, $conf, $panel_args, $context) {
  if (empty($context) || empty($context->data)) {
    $keys = '';
  }
  else {
    $keys = $context->data;
  }

  // Build the content type block.
  $block = new stdClass();
  $block->module = 'search';
  $block->delta = 'form';
  $block->title = '';
  switch ($conf['path_type']) {
    default:
    case 'default':
      $path = 'search/' . $conf['type'];
      break;
    case 'same':
      $path = $_GET['q'];
      $path = str_replace($keys, '', $path);
      break;
    case 'custom':
      $path = $conf['path'];
      break;
  }
  $prompt = $conf['override_prompt'] ? $conf['prompt'] : NULL;
  $form_state = array(
    'no_redirect' => TRUE,
    'args' => array(
      url($path),
      $keys,
      $conf['type'],
      $prompt,
    ),
  );
  ctools_include('form');
  module_load_include('inc', 'search', 'search.pages');
  $form_id = $conf['form'] == 'simple' ? 'ctools_search_form' : 'search_form';
  $block->content = ctools_build_form($form_id, $form_state);

  // We do the redirect manually because the built in search form is stupid
  // and won't redirect even though action is a valid argument for it.
  if (empty($block->content)) {
    drupal_goto($path . '/' . $form_state['values']['processed_keys']);
  }
  return $block;
}