Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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;
}
Comment | File | Size | Author |
---|---|---|---|
#1 | 844912-token-search-tokens-D7.patch | 3.65 KB | Dave Reid |
Comments
Comment #1
Dave ReidComment #2
Anonymous (not verified) CreditAttribution: Anonymous commentedIt makes perfectly sense. Those tokens are not specific for Opensearch feed, and they can used from any module that needs them.
Comment #3
Anonymous (not verified) CreditAttribution: Anonymous commentedAren'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 :-)).
Comment #4
Dave ReidThey'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.
Comment #5
stephanbauer CreditAttribution: stephanbauer commentedIs 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