Skip to main content
[Edit removed during grace period]; edited tags
Source Link
RajeevK
  • 3.1k
  • 1
  • 18
  • 34
Source Link
RajeevK
  • 3.1k
  • 1
  • 18
  • 34

Show create content menu item to ananymous users but call URL for login/register popup on click

I thought it would be simple to do, but after lots of searching I couldn't find exact solution for it.

So the issue is, I have 2-3 main menu items which I have to show to anonymous users but have to call a URL(for login/register popup) & prompt for login or register if they click on them.

Best solution I found for create content link "node/add/node-type" was something like --

function THEME_preprocess_page(&$vars, $hook) {
    global $user;
    # if url starts with "add" and current user is anonymous
    if (arg(1) === 'add' && $user->uid === 0) {
          # redirect to login page
          drupal_goto('user/login');
          exit;
    }
}

It didn't work & it says - "$base_path has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer."

This is a very important functionality thing & I don't know how people resolve it. Can I get any suggestion for it ?