3

I have several type of nodes for content that is contributed by authenticated users. I would like the links to be visible to anonymous users but if they click the link to have it redirect them to the user log in page and if at all possible have the destination send them to the node creation page? I can use either a custom module or rules. How do I do this? Also, how do I have the flag links do this too?

2

If you use the LoginToboggin Module. It Provides a login form on Access Denied pages for non-logged-in (anonymous) users, instead of just the standard "Access Denied". (Also, good for admins, who forget to login when trying to access admin areas too)

1

go for the site-information page in Configuration. In the Error-pages section give the path /?q=user in the text field, titled, Page Not Found 403(access deneid). This will help redirecting anonymous user to user login page.

1

I advise you to use Content Access + ACL does not show some parts of the site.

1

First I created a block that uses theme_links to create the menu.

/**
* implements hook_block_view()
*/
function helper_block_view($delta = ''){
  $block = array();
  switch ($delta) {
    case 'helper_user_links':
      $block['subject'] = NULL;
      $block['content'] = array(
        '#markup' => theme('links', array(
          'links' => helper_user_links(),
          'attributes' => array(
            'class' => array('links', 'inline', 'clearfix', 'user-links', 'menu'),
            'id' => 'user-links',
          ),
          'heading' => array(
            'text' => t('User menu'),
            'level' => 'h2',
            'class' => array('element-invisible'),
          ),
        )),
      );
    break;    
  }

  return $block;
}

Then I created a list of paths in the function that uses another function to format the links array.

function helper_create_links() {
  $links = array();

  $paths = array(
    "node/add/business" => 'Add Business Listing',
    "node/add/annotation" => 'Create Annotation',
    "node/add/discussion" => 'Create Discussion',
  );
  $links = helper_make_links($paths);

  return $links;
}

Last I created a function that tests if the user has access to the link. If the user doesn't have access the link, it is written as 'user/login' with a query that sets the destination to the original link's destination and a css class added that can be used to deactivate the active class.

function helper_make_links($paths) {
  $links = array();
  if (!empty($paths)){
    foreach ($paths as $path => $title) {
      $item = menu_get_item($path);
      if ($item && $item['access']) {
        $links[] = array(
          'title' => !empty($title) ? $title : $item['title'],
          'href' => $item['href'],
        );
      } else {
        $links[] = array(
          'title' => !empty($title) ? $title : $item['title'],
          'href' => 'user/login',
          'attributes' => array(
            'class' => array('deactivate',),
          ),
          'query' => array(
            'destination' => $item['href'],
          ),
        );
      }
    }
  }
  return $links;
}
0

There is nice module Redirect 403 to User Login.

Redirect the HTTP 403 error page to the Drupal /user/login page with an optional message that reads:

"Access denied! You must login to view this page."

Also, the desired page is appended in the url query string so that, once login is successful, the user is taken directly where they were originally trying to go.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.