Display node in views, but turn off node page

I am creating a Reviews block with a new content type and Views module. The problem is that Drupal creates a separate page for each review, and users can access the page if they know its identifier (or find the page in SERP).

Is it possible to disable node pages for a certain type of content, but enumerate the nodes in the Views block? A standard 404 Drupal page would be perfect.

Thanks!

+4
source share
2 answers

This is difficult because you cannot use hook_node_access () (the view mode is never skipped so that you can’t define between the teaser and the full pages). A quick dirty way to do this would be hook_node_view () :

function MYMODULE_node_view($node, $view_mode, $langcode) { if ($node->type == 'my_node_type' && $view_mode == 'full') { drupal_not_found(); } } 

There is probably the best “Drupal” way to do this, but this will be done as a last resort.

+3
source

This answer is for Drupal 6.x, but it is probably very similar to Drupal 7 ...

Chaos Tools and Panels modules for Drupal can do this. Using the Chaos Tools add-on module "Page Manager" you can enable the page "node_view" in the section "Managing pages ..." (Creating a site → Pages).

After the "node_view" page is enabled, you will add a "Variant" (for example, "Title:" User without administrator rights ") with" Selection rules "and set the criteria to" Node Type ", then restrict it to the type of your content (for example , recommendation).

After that, the "user role" will require another "selection rule". At the same time, select both anonymous and authenticated user roles.

Next, continue the setup and select the “Single Column” layout, and then click the “gear” icon in the “Middle Column” when selecting the contents of the panel. Then you can specify an existing node (for example, a 404 node page).

Further, I would recommend setting up another “Variant” (for example, “Header User”) on the “node_view” page with the “Selection Rules” criteria set for your content type and setting user criteria for the administrator role) or user ID # 1. Then, instead of adding a 404 node as content to your panel page, you can add a "current node viewed" to the panel content. This way, administrators can see the node pages, and regular users will be redirected to your 404 page.

+1
source

All Articles