0

I have the following code in the View's header (Global: Text area).

<?php
  global $user;
  if (user_access('create page content', $user)) {
    $output = l(t('Publica un artículo nuevo'), 'node/add/articulo');
    print $output;
  }
?>

If I log in as admin I can add an "articulo" by clicking on the link that the PHP generates in the header of the view. However if I log in as a different role I can still add an "articulo" by using the navigation menu but for some reason the link generated by the code above disappears i.e. the link is only visible for the admin role and I want it to be visible for other roles as well. I have tried changing the permissions for the different roles but it has not worked. If the other roles can create content from the navigation menu why does this link disappear for them. Do I need to change something within the view or ...?

Thanks in advance.

  • Also note that if you don't pass in a user to user_access() it automatically checks for the current user. So you don't need to use the global $user in this case. – rooby May 1 '14 at 12:03
1

As per your code , you need to make sure two things...

  • Logged in User should have create page content access in permissions since your code checks for that permission
  • Logged in User should also have access to create articulo content "node/add/articulo" since l function checks for user access of the path he is trying to access.

Make sure logged in user role have both permissions in your permissions list. Clear cache and rebuild permissions before verifying.

In your case , Make sure the different role you are mentioning has "create page content" permission.

  • Perfect. Thank you very much. I copied and pasted the code from another post and I forgot to change the condition from 'create page content' to 'create articulo content'. – Blas Feb 17 '14 at 9:19

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.