We added search module tokens to opensearch.module, and we can probably move most of them into token.module since its a core module.

/**
 * Implements hook_token_list().
 */
function opensearch_token_token_list($type = 'all') {
  $tokens = array();

  if ($type == 'search' || $type == 'all') {
    $tokens['search']['search-keywords'] = t('The keywords of the current search request.');
    $tokens['search']['search-keywords-raw'] = t('The unfiltered keywords of the current search request.');
    $tokens['search']['search-module'] = t('The module handling the search routine.');
    $tokens['search']['search-name'] = t('The title of the search routine.');
    $tokens['search']['search-path'] = t('The URL alias of the search page.');
    $tokens['search']['search-url'] = t('The absolute URL of the search page.');
  }

  return $tokens;
}

/**
 * Implements hook_token_values().
 *
 * @param $object
 *   The module name of the search routine.
 */
function opensearch_token_token_values($type, $object = NULL, $options = array()) {
  $values = array();

  if ($type == 'search') {
    $name = module_invoke($object, 'search', 'name');
    $values['search-keywords-raw'] = trim(search_get_keys());
    $values['search-keywords'] = check_plain($values['search-keywords-raw']);
    $values['search-module'] = $object;
    $values['search-name'] = $name;
    $values['search-path'] = drupal_get_path_alias("search/$object");
    $values['search-url'] = url($values['search-path'], array('alias' => TRUE, 'absolute' => TRUE));
  }

  return $values;
}
CommentFileSizeAuthor
#1 844912-token-search-tokens-D7.patch3.65 KBDave Reid
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dave Reid’s picture

Status: Active » Needs work
FileSize
3.65 KB
Anonymous’s picture

It makes perfectly sense. Those tokens are not specific for Opensearch feed, and they can used from any module that needs them.

Anonymous’s picture

Aren't the tests already written for Opensearch enough? As far as I can see, those tests don't change, passing from Drupal 6 to Drupal 7, if not for the function that is called to get the token replacements.

Am I missing anything? If the tests just need that change, I can provide a patch (if there is interest in that :-)).

Dave Reid’s picture

They're a very good start and I'll likely just copy them over, but we need to be able to test the search keywords token, which we'll need to add output to the bottom of a search page or something.

stephanbauer’s picture

Is there an update on this? The OpenSearch module is waiting for it to be integrated until it's ported to D7
#667874: OpenSearch Drupal 7 port
It seems like search_get_keys() was removed since then.

Thanks
sb