Hi, thanks for this module. It has been very important in a CRM/intra project I built recently.

I noticed that when showing search results of node attachments (using the helper functions "search_files" and "filefield"), the links always point to the actual file and not the node.
Can't we have both? It would be very important for my project.

CommentFileSizeAuthor
#6 search-result.tpl_.php_.txt2.67 KBbibo
#3 816770.patch780 bytesjhodgdon

Comments

jhodgdon’s picture

That does seem like a reasonable thing to add... I'm in development mode now for the next 6.x version of Search by Page, so I'll figure out a way to put this in... Though I'm not sure exactly how, since the search result information structure comes from the Search module and is fairly standardized.

Hmm... I think what I will do is add a 'related_node' component to the search information returned by the Attachments module, and then in your theme you can do whatever you want with that.

So it would show up in the search-result.tpl.php template (which your theme can override) as an additional component $info_split['related_node'], which you could then display however you wanted to.
http://api.drupal.org/api/drupal/modules--search--search-result.tpl.php/6 for more documentation on the template file.

bibo’s picture

Wow, I couldn't hope for more. Your approach sounds perfect :)

jhodgdon’s picture

Status: Active » Needs review
StatusFileSize
new780 bytes

Slight change. It doesn't end up in $info_split['related_node'] but in $result['related_node'].

Here's a patch that should add it there. Can you see if it serves your purpose?

bibo’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Status: Patch (to be ported) » Reviewed & tested by the community

Patch works just as expected :).

In case others want to do this too, here is how I themed the search-result.tpl.php-file:

 /*
 * .... (lots of comments about variables) .... 
 * @see template_preprocess_search_result()
 * 
 *
 * search_by_page added extra variable: $result['related_node'] 
 */
 
  $related_node = $result['related_node'];
  if($related_node->title){
    $info .= ' <span class="attachment-belongs-to">'.t("This item is related to: "). l($related_node->title, 'node/'. $related_node->nid).'</span>';
  }
?>
<dt class="title">
  <a href="<?php print $url; ?>"><?php print $title; ?></a>
</dt>
<dd>
  <?php if ($snippet) : ?>
    <p class="search-snippet"><?php print $snippet; ?></p>
  <?php endif; ?>
  <?php if ($info) : ?>
  <p class="search-info"><?php print $info; ?></p>
  <?php endif; ?>
</dd>

In other words, I just added these 3 lines:

  $related_node = $result['related_node'];
  if($related_node->title){
    $info .= ' <span class="attachment-belongs-to">'.t("This item is related to: "). l($related_node->title, 'node/'. $related_node->nid).'</span>';
  }

Since I'm appending the text to the already included $info-var, even these few lines of code could live somewhere else, like a preprocess function in template.php.
Works great for my needs.

Thank you jhodgdon!

EDIT: switched to < code > tags to avoid filter mess.

jhodgdon’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Needs review » Patch (to be ported)

Thanks for testing! I've added that patch (plus an addition to the README file) to the 6.x-dev release, and I expect to have a new version of Search by Page 6.x out in the next week or so.

So this is fixed in 6.x-dev now. It also needs to be ported to the 7.x-dev version of Search by Page.

One note: due to the quirks of formatting in issue comments, your solution for the template file didn't come through very well. You might consider adding the whole file as an attachment, although your note at the end about the 3 (well, actually 4) added lines is clear enough.

bibo’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)
StatusFileSize
new2.67 KB

Okay, I'll add the template file as an attachment here :)

jhodgdon’s picture

Status: Patch (to be ported) » Fixed

This patch has also been committed to the Drupal 7 development version of SBP Attachments.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.