Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9022755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:35:49+00:00 2026-06-16T05:35:49+00:00

I am having a very strange problem with drupal. I have a custom module

  • 0

I am having a very strange problem with drupal. I have a custom module that does a goto if you view a node of a certain type (see code below). The problem is, after a while I get in an infinite loop where the datafile_flow_node_view is called infinitely (happens on every page,also the ones that don’t contain the CT).

The most interesting part is (altough I don’t use the search anywhere) that the view mode is search_index. After I disable the search module, the problem dissapears. When I reanable the module, the problem is gone for a certain time, then it returns (I don’t know when and why).

Can anyone shed some light on why this happens ?

function datafile_flow_node_view($node, $view_mode, $langcode) {
  if ($node->type == 'datafile') {
    drupal_goto('node/' . $node->nid . '/edit');
  }
}

@EDIT apparently this happens during running the cron. Is there a way to avoid the hook_node_views from beeing executed during cron ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:35:50+00:00Added an answer on June 16, 2026 at 5:35 am

    There isn’t a way to avoid hook_user_view() is executed during cron tasks, but you can avoid redirecting the users to another URL when hook_node_view() is invoked to build the node content used to populate the search index.

    function mymodule_node_view($node, $view_mode, $langcode) {
      if ($view_mode != 'search_result') {
        if ($node->type == 'datafile') {
          drupal_goto('node/' . $node->nid . '/edit');
        }
      }
    }
    

    Generally speaking, it is a bad idea to call drupal_goto() inside hook_node_view(); the hook is supposed to change $node->content, not to redirect users.

    What happens is that:

    • During cron tasks, the Search module updates its index
    • The Node module updates the search index, and to do this calls node_view(), which invokes any implementation of hook_node_view(), including the one you shown
    • As drupal_goto() is called during cron tasks, Drupal has problems

    The assumption that hook_node_view() is invoked when users are viewing a node is not correct. The only moment you are sure users are viewing a node is when the page callback for node/%node is called.

    What you can do is implementing code similar to the following one. (I am writing simplified code just to show the correct way to do it.)

    function datafile_flow_menu_alter(&$items) {
      if (isset($items['node/%node'])) {
        $items['node/%node']['page callback'] = 'datafile_flow_node_view';
      }
    }
    
    function datafile_flow_node_view($node) {
      if ($node->type == 'datafile') {
        drupal_goto('node/' . $node->nid . '/edit');
      }
    
      return node_page_view($node);
    }
    

    The code is simplified because it makes the assumption the page callback is node_page_view() (the default used by Drupal), and no module changed it. It would be possible to write code that don’t make any assumption about that, and the arguments used from that page callback. (It is left as exercise to the readers. ;))

    References

    • node_search_execute()
    • node_view()
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im having a very strange problem, i have a complicated view that returns incorrect
I've been having a very strange problem. I have a test class that subclasses
I am having a very strange problem, I have this file for User#show view:
I am having a very strange problem in a simple program and have been
I'm having a very strange problem that may be the result of my ignorance
I'm having a very strange problem with my custom listview. This Listview shows a
I am having a very strange problem with pound signs displaying incorrectly (or not
I'm having a very strange problem. I'm using dfs-datastores Pail abstraction to write data
I have been having a small problem that I can't by-pass it, I keep
I'm having very strange problem with Internet Explorer 7 and 8. For example if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.