Download & Extend

Allow nodereference_url links to set destination param

Project:Node Reference URL Widget
Version:6.x-1.2
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

It'd be great to have the node/add form automatically return to the page on which the "Post a new whatever..." link was originally clicked. here's a patch that makes that possible.

AttachmentSize
destination.patch3.76 KB

Comments

#1

Tweaked version that splits the actual link-building into a helper function. This would allow other modules to display the links in a sidebar block or some custom location.

AttachmentSize
destination.patch 4.3 KB

#2

As an extra bonus, this version of the patch works.

AttachmentSize
destination.patch 4.36 KB

#3

Status:needs review» needs work

I really like the functionality added by this patch.

It looks like this patch introduces redundant options. There's no need for "Create a link on referenceable content" if there are options for "Show on teaser" and "Show on full view". We should consolidate these into a single set of checkboxes such as:

Create a link on referenceable content:
  [  ] For teaser node view
  [  ] For full node view

It also seems like the additional new function can't actually be called by other modules to display the link in some custom location, because the teaser and full node view check is still within that function, so if both teaser and full node view links are disabled, it won't return a link. I think a more appropriate function signature would probably omit the $teaser variable entirely and pass in the $node and $field:

<?php
/**
* Build an individual link.
*/
function nodereference_url_field_link($node, $field) {
 
$link = array();
  
// Build link array.
  
return $link;
}
?>

And then a separate function for creating a straight-up link such as:

<?php
/**
* Build a printable HTML link to create a new node while populating a node reference field.
*/
function nodereference_url_create_link($node, $field_name) {
 
$field = content_fields($node->type, $field_name);
 
$link = nodereference_url_field_link($node, $field);
  return
l($link['title'], $link);
}
?>

#4

Freshly rewritten, pretty much the way you outline. I'd like to take a moment to shake a fist at the difference between a field and a field instance, but it all sorts itself out in the end!

AttachmentSize
destination.patch 6.25 KB

#5

Status:needs work» needs review

#6

Status:needs review» needs work

Getting there... we need to update the validation code in nodereference_url_node_link_validate() since the 'enabled' value no longer exists. This change also requires a hook_update_N() function to change the existing variables on sites, lest this module will suddenly stop working on all existing sites after updating.

#7

Rough version, but it's a stake in the ground -- update function and corrected boolean checks. Woot.

AttachmentSize
destination.patch 8.98 KB

#8

Nope, that version didn't work. Doh!

The attached one should, though. In the meantime, I've learned about CCK update functions. Yay!

AttachmentSize
destination.patch 8.46 KB

#9

Status:needs work» needs review

#11

Some final tweaks - properly sets the 'destination' key, and sets the update to 6001, not 6006 -- I did a few rounds of testing on it and had to keep incrementing the update function locally.

AttachmentSize
destination.patch 8.53 KB

#12

Nice! That's one clean looking update function. I'll test this out when I get a chance.

#13

Very nice feature!

#14

Status:needs review» reviewed & tested by the community

Patch works great. Thanx!

#15

I have applied the patch, the update went ahead without error and the functionality works as described. Thanks!

#16

I'm gonna apply this sucka, because I want & need the shiny that appears in eaton's video: http://www.lullabot.com/articles/photo-galleries-views-attach

Edit: looks to be working fine after some *basic* testing (my specific use case only) - however I do think the text in the "return path" selector is a bit flaky. It needs to be clearer what each of these cases is. Myself, I'd assumed that the "page the link was clicked on" meant the same as the "node being referenced" and in my case it wasn't altogether clear which I ought to pick. Given that trial & error with fields isn't simple, I think this requires a little attention :)

#17

Any suggestions on what wording would be clearer? "The page the link was clicked on" could be a listing view, the front page, or any other place that the referenced node appears. For example, let's say you have a view at the url "galleries", and node 1 is a gallery. On the "gallery" page you click a link to create a new image in gallery 1.

"Default" means you would stay on the newly posted node's page.
"Referenced node" means you would be taken to node/1, the gallery node.
"Page the link was clicked on" means you would be taken back to "galleries", because you were on that page when you clicked the link.

#18

this module works fine, should be in the next release! :)

"Default" could be "No redirect"?
"Page the link was clicked on" could be "Previous page"?

thanks for this code, excellent functionality

#19

+1 to the wordings in #18.

#20

I'm sympathetic to anyone on Windows who find the patching process a bit tedious - so if anyone needs the patched version of the .module and .install files, I'm including them in this attachment.

AttachmentSize
nodereference_url_updates.zip 4.4 KB

#21

Status:reviewed & tested by the community» needs work

A couple things I've found so far:

- nodereference_url_update_6001 should be nodereference_url_update_6100.
- The "Fallback behavior" value is lost on upgrade.
- The $teaser variable is not available in the nodereference_url_build_link() function, meaning that teaser is always evaluated to FALSE (so the full page setting actually controls the teaser setting).

I'm working on a reroll, but I'm a little sad that this has been RTBC for nearly 2 months, yet there are rather critical problems with the patch. :-(

#22

Doh, scratch "The "Fallback behavior" value is lost on upgrade," that was cause by my attempts in another patch to get autocomplete working.

#23

Status:needs work» fixed

Alrighty, I applied this patch with the following changes:

- Renamed update to nodereference_url_update_6100(), since this is an update function with the 1.x branch (usually 600x is reserved for upgrading from Drupal 5).
- The $teaser variable is passed into nodereference_url_build_link(), so the "Create link on teaser" checkbox now works.
- I used most of Boris's suggestion from #18. The options are now "The new node (no redirect)", "The referenced node", and "Previous page".
- In the update function, the $field['widget']['node_link']['enabled'] option is unset, since this setting is no longer used.
- Clarified docs slightly and grouped all the link settings within a fieldset rather than #type = 'item'.
- The link title validation was broken by the change, it's now required again if either the teaser or full link option is enabled.

AttachmentSize
nodereference_url_redirect.patch 8.56 KB

#24

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

nobody click here