Getting the following error whenever I perform a search on Drupal 7 RC4

Notice: Undefined index: type in fusion_core_preprocess_search_result() (line 251 of /themes/fusion/fusion_core/template.php).

Comments

realityloop’s picture

Status: Active » Needs review

Resolved by adding isset() as follows:
Before:

  // Provide alternate search result template.
  $vars['template_files'][] = 'search-result-' . $vars['type'];

After:

  // Provide alternate search result template.
  $vars['template_files'][] = 'search-result-' . isset($vars['type']);
syntax-2’s picture

imho:
$vars['template_files'][] = 'search-result-' . $result['node']->type;
or
$vars['template_files'][] = 'search-result-' . $result['type'];

"$result['node']->type" is a system name of content type
"$result['type']" is a user name of content type

i prefer first one ;-)

coltrane’s picture

Status: Needs review » Postponed (maintainer needs more info)

What are the steps? I can't reproduce this, so it'd be helpful to know how you have your site configured and what you are searching for that results in this. Or, try the latest dev release and confirm if this is still an error.

syntax-2’s picture

@coltrane
latest dev version (April 4, 2011 - 00:09)
Notice: Undefined index: type in fusion_core_preprocess_search_result() (line 250 of /var/www/drupal-7.0/sites/all/themes/fusion/fusion_core/template.php).

acquia-marina theme's search box -> one item search result list -> click at node title link -> node page with Notice like above

only for not logged user, for administrator is ok (there is no notice)

coltrane’s picture

Status: Postponed (maintainer needs more info) » Active

Thanks, that helps! I can duplicate now. It's on the first request after clicking through from the search result page, a refresh of the node doesn't show the error (since the dsm happened in the tpl it appeared upon following request).

coltrane’s picture

In Drupal 6 $vars['type'] is the result type 'user' or 'node' (from http://api.drupal.org/api/drupal/modules--search--search-result.tpl.php/6) but in Drupal 7 that property doesn't exist (http://api.drupal.org/api/drupal/modules--search--search-result.tpl.php)

We could instead add in the human-readable node type or make the node or user distinction based on if $info is set, since it supposedly does not apply to user searches. Thoughts?

aquariumtap’s picture

Status: Active » Needs review
StatusFileSize
new470 bytes

Thanks everyone. Coltrane helped me reproduce this over IRC. Seems 'type' was renamed to 'module' in D7.

For documentation's sake: the functionality that was broken (and throwing the error) creates a template suggestion for different search result types.

Themers can style the Content and Users search result tabs differently by duplicating search-results.tpl.php, then renaming the dup to either of these:

  • search-result-node.tpl.php
  • search-result-user.tpl.php
coltrane’s picture

Status: Needs review » Reviewed & tested by the community

Yep, good catch! Tested and it no longer shows the error.

aquariumtap’s picture

Status: Reviewed & tested by the community » Closed (fixed)

Great. Patch committed to HEAD.