Here is the page:

Notice the two links that create new content (one under "Why Choose Us", one under "Testimonials). I don't want the links visible to users who do not have permission to view the linked page.

I created the links by adding the HTML to the Header of each View. Is there some PHP I can put there instead, or is there another way to create that link (a module perhaps)?



4toddt’s picture

Both Views and Menus seem to have this functionality built in, but I can't figure out how to implement it in the Header of a View.

payamspot’s picture

I think this is the way you should do it:

First, create a new view with the content you want ("add content" link) and the permission you want. Then in the header of the view you had before, add an item as "Global: View area" and choose the view you created earlier.

Hope it helps.

4toddt’s picture

Thanks. I'll try that. If anyone has a more direct approach, I would be interested in hearing that as well.

4toddt’s picture

I created a view called "Create links." It is based on the content type article with "Items to display" limited to one. I created a display of type "attachment" and rewrote the output of the "Title" field to become a link to create a new testimonial. I then attached the "Create links" view to the header of the "Testimonials" view. Unfortunately, the link still appears for unauthenticated users.

Even if I could get this method to work, I find it unsatisfying. I would really like to input some PHP into the header that would check permissions before displaying the link. How does Drupal typically handle this?

4toddt’s picture

I'm looking into using a Drupal function like l() or url(). Am I on the right track? If someone could give a line of PHP that would do what I need I would be eternally grateful.

4toddt’s picture

  global $user;
  if (user_access('create page content', $user)) {
    $output = l(t('Add new page'), 'node/add/page');
    print $output;

Just change "page" to the appropriate content type (all three places).

For more info, see SweenyTodd's post here: