Agaric Design Collective

Provide an 'Add New' link on a simple view for easily creating more content to list

agaric-benjamin-add-link.png
Average: 3 (2 votes)
By Benjamin Melançon
on 17 Nov
0 comments

Key words and phrases

Providing an 'Add New' link on a simple view to create more content adding content to views easily admins need links to contribute additional content to views listing pages node types listing with add more link easy

Tags

Description

It's a common situation– you create a simple view that may do little more than filter on one content type in order to get a listing of press releases or links or recipes.

Sure, you can explain to your client and users that going to "Create content" and clicking press release or link or recipe will, when the post is submitted, get it automatically listed on this Views page. And that's pretty nice. But it's a lot more intuitive if the link to create relevant content were right on the view itself.

This bit of code, put into a view's footer text area with an input format of PHP code, will do just that, and make make life a little easier for your administrators.

<?php
global $user;
if (
in_array('admin', $user->roles)) {
  print
l(t('Add new link'), 'node/add/link', array(), 'destination=links');
}
?>

In this case the view is made up of a link content type (it happens to be a list view for nodes that have only one field, a web address, with a node title made into the link title through the magic of token module). The path to the view is example.com/links. This explains both the path and the query parameters of the link function.

It could just as easily by "Add new story", 'node/add/story, and 'destination=view/stories' for your basic view.

@TODO:

This should use user_access('create CONTENT_TYPE') rather than the global $user in roles array check for the administrative role.

Agaric should put this whole thing into a module – and for Drupal 6, maybe even contribute as an extension to Views 2, if there's not already something like this in that amazing module – and have it automatically look for simple views based on one or two (or more?) content types and offer to add "Add [content type]" links to the footers of page views (and blocks?), looking up the path information for the user.

 

Post new comment
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <small> <pre> <strike> <sub> <sup> <kbd> <s>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.