home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (search_extra_type.module)

This example Drupal source code file (search_extra_type.module) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

array, conditions, dummy, entry, function, keys, null, php, result, results, return, search_extra_type_conditions, title, type

The search_extra_type.module Drupal example source code

<?php
// $Id: search_extra_type.module,v 1.3 2010/08/18 18:40:50 dries Exp $

/**
 * @file
 * Dummy module implementing a search type for search module testing.
 */

/**
 * Implements hook_search_info().
 */
function search_extra_type_search_info() {
  return array(
    'title' => 'Dummy search type',
    'path' => 'dummy_path',
    'conditions_callback' => 'search_extra_type_conditions',
  );
}

/**
 * Test conditions callback for hook_search_info().
 */
function search_extra_type_conditions() {
  $conditions = array();

  if (!empty($_REQUEST['search_conditions'])) {
    $conditions['search_conditions'] = $_REQUEST['search_conditions'];
  }
  return $conditions;
}

/**
 * Implements hook_search_execute().
 *
 * This is a dummy search, so when search "executes", we just return a dummy
 * result containing the keywords and a list of conditions.
 */
function search_extra_type_search_execute($keys = NULL, $conditions = NULL) {
  if (!$keys) {
    $keys = '';
  }
  return array(
    array(
      'link' => url('node'),
      'type' => 'Dummy result type',
      'title' => 'Dummy title',
      'snippet' => "Dummy search snippet to display. Keywords: {$keys}\n\nConditions: " . print_r($conditions, TRUE),
    ),
  );
}

/**
 * Implements hook_search_page().
 *
 * Adds some text to the search page so we can verify that it runs.
 */
function search_extra_type_search_page($results) {
  $output['prefix']['#markup'] = '<h2>Test page text is here</h2> <ol class="search-results">';

  foreach ($results as $entry) {
    $output[] = array(
      '#theme' => 'search_result',
      '#result' => $entry,
      '#module' => 'search_extra_type',
    );
  }
  $output['suffix']['#markup'] = '</ol>' . theme('pager');

  return $output;
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal search_extra_type.module source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.