Sometimes the content types we created are only used in Views. We don’t want to have the node view page for those content. The following solution would turn those unwanted node view pages to 404 not found.
Create a custom module and implement the hook_node_view() as follow.
function <module>_node_view($node, $view_mode, $langcode) { if ($node->type == '<content-type>' && $view_mode == 'full' && !user_access('edit any <content_type> content')) { drupal_not_found(); drupal_exit(); } }
Replace the <content-type> with the content type machine name. Enable the module and clear the cache. You will find that those node view pages are not found but the edit tab is still valid if the logged in user has the proper permission. You can also restrict the access by a different permission.
Done =)
Reference: StackOveflow – Display a node in Views, but disable the node page
Very good idea.
I’m using to redirect on my custom view instead of using 404:
drupal_goto(‘real url’);
(you get an useless parenthesis 😉
LikeLiked by 1 person
I have updated the code. thanks of pointing out that! =)
LikeLike