0

I'm using Drupal 7 : with Search API

In this I'm using the token [search-api-saved-search-result:url] which I take it should output the Url of the relevant nodes. The Urls are correct except the have 'cron.php' text in them . ie 'www.example.com/cron.php/node/1234' ; making them not work.

this is the code in the Search API module.

case 'search-api-saved-search-result':
  $d = $data['search_api_saved_search_result_info'];
  if (!empty($d['search']) && !empty($d['entity'])) {
    $search = $d['search'];
    $index = $search->index();
    $item = $d['entity'];
    foreach ($tokens as $name => $original) {
      if ($name == 'id' && ($id = $index->datasource()->getItemId($item))) {
        $replacements[$original] = $id;
      }
      elseif ($name == 'label' && ($label = $index->datasource()->getItemLabel($item))) {
        $replacements[$original] = $label;
      }
      elseif ($name == 'url' && ($url = $index->datasource()->getItemUrl($item))) {
        $url['options'] += $url_options;
       $replacements[$original] = url($url['path'], $url['options']); // $replacements[$original] = url('http://www.rcnbulletins.com/', $url['options']);
      }
    }
    if (($url_tokens = token_find_with_prefix($tokens, 'url')) && ($url = $index->datasource()->getItemUrl($item))) {
      $replacements += token_generate('url', $url_tokens, $url, $options);
              }
  }
  break;

I'm wondering if this is a bug or something i've missed in admin.

1 Answer 1

0

Here is the solution . thanks to these answers Formatting output of token

/**
* Implements hook_tokens_alter().
*/
function rcn_tokens_alter(&$replacements,  $context){
  // fix urls being outputted with cron.php in the link.
  if(isset($replacements['[search-api-saved-search-result:url]'])){
  $url = $replacements['[search-api-saved-search-result:url]'];
  $newurl = str_replace("cron.php/", "", $url);
  $replacements['[search-api-saved-search-result:url]']  =   check_plain($newurl);
  }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.