I just spent the last couple hours trying to figure out why I was getting a non-sensical SQL error during searches. While looking into it, I finally discovered that the problem is that the documentation for hook_ranking() (both D7 and D8) has incorrect instructions (and example) for how to use the 'join' key. It says that the 'join' value should be a string that will be merged into the SQL query, when in fact it needs to be an array of values, like below:

'join' => array(
  'type' => 'LEFT',
  'table' => 'node_counter',
  'alias' => 'node_counter',
  'on' => 'node_counter.nid = i.sid',
)

I discovered this by looking through core for implementations of hook_ranking() that use the 'join' key, and found one in statistics.module. That led me to finally understand what's happening in node.module's _node_rankings() function, and why that array is needed.

My guess is that at some point in the development process for the ranking hook system, the 'join' key was changed to an array, but the documentation was never updated.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug
Issue priority Major because API documentation is incorrect
Unfrozen changes Unfrozen because it only changes incorrect API documentation
Prioritized changes The main goal of this issue is fixing broken documentation.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

BarisW’s picture

Status: Active » Needs review
FileSize
1.44 KB

Good catch, here's the patch for D8. Needs backport to D7.

j. ayen green’s picture

Assigned: Unassigned » j. ayen green
xjm’s picture

Component: node.module » node system
Issue summary: View changes

(Merging "node system" and "node.module" components for 8.x; disregard.)

jhedstrom’s picture

Priority: Normal » Major
Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
Issue tags: +Documentation

#1 looks good to me. Adding the docs tag, and a beta phase evaluation.

(I think API documentation bugs are major).

alexpott’s picture

Version: 8.0.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)
Issue tags: +Needs backport to 7.x

Committed 8790ec0 and pushed to 8.0.x. Thanks!

Thanks for adding the beta evaluation for to the issue summary.

  • alexpott committed 8790ec0 on 8.0.x
    Issue #2017433 by BarisW: The documentation for hook_ranking() is wrong
    
LinL’s picture

Assigned: j. ayen green » Unassigned
Status: Patch (to be ported) » Needs review
FileSize
1.42 KB

Here's a backport for 7.

xjm’s picture

Issue tags: -Needs backport to 7.x +Needs backport to D7
shashikant_chauhan’s picture

Status: Needs review » Reviewed & tested by the community

#7 looks good to me.

David_Rothstein’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 7.x - thanks!

  • David_Rothstein committed 56bbd4b on 7.x
    Issue #2017433 by LinL, BarisW, coredumperror: The documentation for...

Status: Fixed » Closed (fixed)

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