The query in node_reference_field_prepare_view() gets the list of all published references.

However, sites would want to alter this query for different reasons using hook_query_alter(). In order to properly identify this query, could an 'id' be added as meta data, at the least?

Use case:
* Display all node references, including those that are unpublished, to all users
* But unpublished nodes on their own show 403 to normal users.

Attaching patch. I've also added the $field as a meta data as that could be useful.

Comments

rickvug’s picture

Status: Active » Needs review

Subscribe. This patch makes a lot of sense. I'm tempted to mark RTBC but I'll leave at needs review for now. #1139238: Manually alter the node reference list prior to query execution? could also use the query meta data so that node reference queries could be better targeted.

s_leu’s picture

Status: Needs review » Closed (duplicate)

closing this as duplicate of #1139238: Manually alter the node reference list prior to query execution?

girishmuraly’s picture

Status: Closed (duplicate) » Needs review

I can't see how this is a duplicate. #1139238: Manually alter the node reference list prior to query execution? is relating to the query that produces references when using a node reference field in edit mode as far as I understand. This ticket is regarding altering the query that fetches referenced entities.

Swtiching status back for the patch in #0

yched’s picture

Status: Needs review » Fixed
StatusFileSize
new1.33 KB

Rerolled after #1354580: Unpublished nodes are not displayed, added similar code in user_reference, and committed the attached patch.

Thanks !

girishmuraly’s picture

@yched, I am unable to apply the last patch (#4) onto 2.x branch or 2.0 release. Can you link to your commit please?

[girishn@gn-dev references]$ git apply -v references-field_prepare_view_query-1256280.patch
Checking patch node_reference/node_reference.module...
error: while searching for:
    if (!empty($ids_to_check)) {
      $query = db_select('node', 'n')
        ->addTag('node_access')
        ->fields('n', array('nid'))
        // WHERE n.nid IN (nids to check) AND ...
        ->condition('n.nid', $ids_to_check, 'IN');

error: patch failed: node_reference/node_reference.module:244
error: node_reference/node_reference.module: patch does not apply
Checking patch user_reference/user_reference.module...

The base code seems different.

Rerolling #4

girishmuraly’s picture

Status: Fixed » Needs review

Forgot to change status.

Status: Needs review » Needs work

The last submitted patch, references-field_prepare_view_query-1256280.patch, failed testing.

girishmuraly’s picture

Status: Needs work » Needs review
StatusFileSize
new2.02 KB

Also forgot to attach patch for #5 duh!

yched’s picture

Status: Needs review » Fixed

Oops - #4 was the correct diff for 7.x-2.x after the commit in #1354580: Unpublished nodes are not displayed - I committed those two locally but forgot to push :-/.
So #4 was not applicable to any 7.x-2.x state available online.

Anyway. Pushed now, 7.x-2.x contains the fix. Sorry all.

girishmuraly’s picture

Thanks @yched

Status: Fixed » Closed (fixed)

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