Hello,

The default implementation of Drupal provides a "Create content" link located beneath the user account menu as well as a list of nodes to edit or delete by accessing the "Content" administration page found beneath the "Administer->Content" menu. While this method may be fine for some users such as administrators or site content managers, it's not necessarily very intuitive for external site account holders who are just site members and don't necessarily understand CMS's and the creation or modification of content.

I currently have setup user profiles using Content Profile and have embedded several views within these profiles to display content related to that user such as an MP3 player with personal playlist, a view of a user's upcoming events etc, a full calendar view etc. My goal is to allow a user to create/modify/delete content right from this profile page, eliminating the need to navigate to these items in the traditional way or understand Drupal administration.

In an effort to make it easier and more intuitive for these profile users to create the above content that will be displayed by these views, I have added code to display links to "Add" new content of the appropriate type within the header of the particular view to the owners of these profiles. I also have provided links to "Edit" or "Delete" the nodes associated with the view. It's much easier to have a "Add new song to playlist" link above the view on the profile page than to navigate to the "Create content" page and choose the "Song" content type and know that this content will be displayed in your personal playlist on your profile page regardless of any help text stating as such.

While building the above links, I have included the current profile path in the "query" attribute using the "drupal_get_destination()" function. The intention is that after adding a new node for instance, the user will be returned to their profile page where they can either add another node or modify other nodes displayed in the view.

The problem is that the default implementation of Drupal redirects to the node being created or edited after submitting it. The "query" attribute in the links I've built are ignored because the creation or modification of nodes has their own redirect to the actual display of node. This isn't always desired as some nodes serve no other purpose other than being displayed by a view and don't always make sense on their own. In the case of a song node for instance, viewing this node at it's URL, node/nid is meaningless and doesn't display anything of value to someone visiting that page other than a filename and description as there is no other related text or anything to make the page meaningful. However, in the context of a View, that node's filename and description have more meaning as they are attached to an MP3 player which displays the title of the song and links it's filename to the player in order to actually play the song.

So with all that, I am wondering first if it is possible to change the behavior of adding or editing nodes to keep them from redirecting to the node display itself except where it makes sense to do so. In addition, this behavior should work differently depending on where it is being initiated. I still want nodes to behave in the default manner when using the "Create content" method to add them or when using the "Content" administration page to edit or delete them. In these cases, displaying the node after adding or editing it is acceptable such as when an administrator is . But when adding or modifying node through a view, I want the user to be returned to the view upon submitting and not to the node itself.

I hope I made sense with all this and I would appreciate any advice someon could give me. Perhaps it's some code in a custom module that I need to intercept during the creation of a node and change the redirect based on some kind of additional parameter?

Thanks in advance!

Comments

nevets’s picture

What does one of your generated links look like?

jastylr’s picture

Thanks for the reply. Here is a sample code snippet that generates a link:

if ($logged_in_user == $user_id) {	
  print '<div class="audio-view-admin-links">Your playlist is empty. ' . l(t('Add Song to Playlist'), 'node/add/audio', array('attributes' => array('query' => drupal_get_destination(), 'html' => 'TRUE'))) . '</div>';
}
else {
  print $node->field_bizprofile_name[0]['view'] . ' has no playlist.';
}

There is additional code but this show the call to Drupal's l() function to create the link.

And here is what is the raw HTML output is:

<a html="TRUE" query="destination=node%2F192" href="/node/add/audio">Add Song to Playlist</a>

The issue is that when adding a new node or even editing one, the user is redirected to the created or edited node and not the destination URL.

Thanks

nevets’s picture

For

  print '<div class="audio-view-admin-links">Your playlist is empty. ' . l(t('Add Song to Playlist'), 'node/add/audio', array('attributes' => array('query' => drupal_get_destination(), 'html' => 'TRUE'))) . '</div>';

I think you want

  print '<div class="audio-view-admin-links">Your playlist is empty. ' . l(t('Add Song to Playlist'), 'node/add/audio', array('query' => drupal_get_destination(), 'html' => 'TRUE')) . '</div>';

Query should be an option to l(), not an attribute.

jastylr’s picture

Okay, correct you are. I originally had a class defined in the attributes array and when I added the destination query I simply put it in the wrong place. I thought that the raw HTML output looked strange as there are not HTML or destination attributes but I simply overlooked it.

Just tried it out and it works as expected. Thanks for saving me a bunch of time!