User login

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

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.

Resolution

Searched words: 
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

Comments

Great Tip Thanks!

This worked perfectly, thanks! I would also like to see this integrated into views.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.