If somebody else is trying to use node reference URL widget's functionality for paths that differ from 'node/add/CONTENT_TYPE/%nid', then you can test my attached patch.
I want to put the node creation form into a Panels pane, but the Panels display has its own path (which differs from the path above for which node reference URL widget has been designed). By the way, my solution allowes Panels panes with node creation forms for different node types (using different nodereference CCK fields) on one Panels display (with one identical path without problems).
All you have to do is to create some (identical) path entries in the new configuration item of your node reference CCK field (which must use the URL widget). I called the textarea 'Custom URLs' and you could enter there things like 'my/custom/path/%nid'. Last step is creating some links (e.g. by using l() function) which offer the referenced node IDs.
Maybe this feature can be integrated in a future relase of node reference URL widget. I have no idea if this feature is interesting for others.
The shared patch contains a short example at top of the file. (That part should not go into a future release, but in a README.TXT or something else.)
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | nodereference_url_custom_paths.patch | 6.38 KB | quicksketch |
| #2 | nodereference_url_custom_paths.patch | 5.15 KB | m_z |
Comments
Comment #1
quicksketchNote that you can already just use ?[name]=[nid] in the URL and Node Reference URL Widget will use that instead, though I think it still only works on the node/add/* path.
BTW, no patch is attached to this issue.
Comment #2
m_z commented2nd trial for adding my patch
Comment #3
m_z commentedNow it seems that my patch is visible in #2.
@quicksketch:
Thank you for your answer.
I read about the ?[name]=[nid] syntax, but I couldn't bring it to work (with my 6.x-1.3 version). What should [name] be filled with?
I checked .module code and I can't find the place where this additional syntax will be handled.
My solution is working (at least for me :)
And I found an old issue (http://drupal.org/node/492980) which could be solved with my patch - so I am not the only person that needs such a feature...
Comment #4
quicksketchI don't like the idea of adding fields for arbitrary node/add paths, at least not in the UI. What I'd recommend doing if you're overriding your node forms with panels is to put your panel paths at node/add/[type], so the URL doesn't change. I don't think the existing mechanism will work for your use-case, since it still checks for node/add being in the URL.
Comment #5
m_z commentedI think that there is a misunderstanding of my intention writing this patch. I'll try to describe it better:
I don't want to override my node forms with panels.
I want to use panel pages with an arbitrary path that may contain (beside other panel panes) one or more panel panes for creating new (and possibly different) content types.
So: one Panels page (e.g. path 'node/%nid/my-custom-panel-page', where %nid is the node ID of my content type C, which should be the reference for other content types A and B) --> panel pane A contains the node add form for content type A (which should be refernced with %nid of content type C) + panel pane B contains the node add form for content type B (which should be refernced with %nid of content type C, too)
In such cases your proposal doesn't work, because I can't give my panel page 2 different paths 'node/add/B/%nid' and 'node/add/C/%nid'. Or am I wrong?
And Yes, you are right. The existing mechanism won't work for my use-case.
That is the reason why my patch #2 adds the following
elseifunder the original code posted in #3:And
// '/^node\/([0-9]+)\/[a-zA-Z_\-0-9]+\/add$/' will find 'node/%nid/%/add'is only an example that I used to test my regular expression.The other parts of my patch are quite easy:
- usage demonstration with hook_menu (must be uncommented to work and shouldn't go into Node Reference URL Widget code)
- adding a textarea in the options section
- storing its value
- validate handler for this textarea
- and the piece of code above (which does the work)
If you (or other community members) don't like this patch, than it is fine for me. It is only an attempt to give something back to this great Drupal community. And in my opinion it is a good relation between 'additional code' and 'extended functionality' - but this is only my opinion.
Comment #6
pkiff commentedI am using Form Block to allow the creation of nodes on other URLs, and thought this patch might help me configure the add node blocks to pick up the NID from the URL being viewed. But I couldn't figure out how to configure the patch. In particular, I'm not clear on what I'm supposed to do to customize the menu hook. And I'm not even clear on where that should go. Should that go in my template.php file?
It is quite possible that Form Block is messing around with the add node code in a way that disrupts the patch, but it sure would be handy for me if it worked.
Any further suggestions or info on this patch would be appreciated.
Thanks,
Phil.
Comment #7
m_z commentedHi Phil,
I don't know Form Block in detail.
As far as I can see you don't have to modify the hook_menu example in the patch, because by using Form Block you already see your node add/edit form at a path differing from standard path (node/add/...).
To make this patch solving your problem, you must figure out where you can find the reference node ID in your path (with the Form Block node add/edit form).
e.g. 'my-path-with-node-add-form/page/3' --> then add as search pattern in nodereference field settings: 'my-path-with-node-add-form/page/%nid'
If you need further help, please describe your problem in more detail (including your path values and their meaning and maybe a screenshot).
Comment #8
pkiff commentedThanks. I don't know Form Block either (!), but am trying to use it as a way of avoiding creating a custom add node form.
Here is the URL I want to pick the NID up from:
~/abstracts/[user]/22
This URL is actually a node view of an "abstract" content type. I could find the same page displayed here:
~/node/22
The [user] part changes depending on who the author of the actual node was. But for troubleshooting purposes, I've eliminated that variable and am trying to get it working just with this URL:
~/abstracts/jsmith/22
On this page, the abstract node 22 gets displayed, and then below it, the add form block display appears for a different content type called "review".
The idea is to have a "review" form displayed at the bottom of each "abstract" so that authorized users can submit reviews of abstracts while at the same time seeing the node output of the abstract they are reviewing.
Here is what I have entered in the config for the node reference field:
abstracts/jsmith/%nid
And from what I can gather, if I can get the above URL to work, then I think I should be able to enter:
abstracts/%/%nid
And I have the fallback behaviour set to use select list. But no matter what I do, I only get the select list.
It is possible that I patched the file incorrectly, since I manually applied the patch using cutting and paste instead of using a proper patch program.
I'm trying to get something up today, so I think I'll use another solution for the time being, but when I have a chance, I can send you more details, including screen shots.
Phil.
Comment #9
m_z commentedAfter reading your first post (about Form Block), I tried it by myself and it worked for me.
Maybe your problem is that ~/abstracts/[user]/22 is an URL alias and not a system path. You said that entering this path gives you the identical output like visiting node/22.
Please try to use
node/%nidas pattern in nodereference field settings section. That should work...My patch was designed for system paths (and not URL aliases). Maybe this could be a further improvement, but I don't know if it is easy to realize.
And beside you nobody is interested in this patch :-(
Good luck :-)
Comment #10
gunzip commentedi've exactly the same need. i have a panels with node edit form and i want it to appears in menu tabs (subtasks) so i cannot use any arbitrary path but i MUST use node/%nid/foobar and I cannot get a nodereference from url in this way.
i think that allowing custom paths would be a great addition to the module.
EDIT: what about a textarea where you can put php code to get the nid ? cck defaults can be set with php code so this behaviour will be consistent with the other standard widgets... (for security you can just sanitize this input with is_numeric()...)
Comment #11
m_z commented@gunzip:
Have you tried my patch?
It should work in your use case.
My solution is easier than writing PHP code to get the default value. By the way: you can use original node reference CCK field if you want to use custom PHP code. Node Reference URL Widget is intended to get this 'default value' from URL...
Comment #12
quicksketchAs I noted above, I don't want to add another field to the UI for this option, considering it's probably in the <5% use case. I definitely won't be adding a PHP field for custom code.
This patch makes it at least *possible* to use other URLs. You can use one of two methods:
1. Simply specify the target in the query string: node/x/add/story?ref=y
2. Specify custom paths you want to support in settings.php:
If using method #2, then the first URL pattern in the list will be used for generating automatic links provided by Node Reference URL Widget.
Comment #13
quicksketchComment #14
m_z commented@quicksketch:
I don't understand what you mean with your sentence in #12
My patch (#2) introduced an additional settings form field (which could be placed in a collapsed fieldset...), but it is NO place for custom PHP code. It is a place to put patterns (like your patterns in
$conf['nodereference_url_paths']) for "simple" Drupal users who are not familiar with editing their settings.php file.But in my opinion your commited patch (#12) is a way to solve this issue.
I have one suggestion for further improvement of your patch (where I have developers in mind).
There are 2 places where you call variable_get('nodereference_url_paths', array('node/add/%type/%nid')):
What about calling a helper function instead, which gives other modules a chance to hook into the 'nodereference_url_paths' array?
Should I open a new issue for that? Do you need further explanation what I mean? The helper function should return the content of
$conf['nodereference_url_paths']+ added array elements which can be provided by other (custom) modules.Without such an opportunity I have to use hook_install to place my own 'nodereference_url_paths' elements into
$conf['nodereference_url_paths']by writing such nasty things like:without a way of cleaning it safely with hook_uninstall (because I don't know the paths that were added by other modules in a similar manner) AND with the risk that an entry in settings.php will override my settings.
If each module would make use of settings.php to set variables this file would be a mess...
Please don't misunderstand me: I'm not a native English speaker and I'm only interested in a good solution which helps the Drupal community (including you and me :).
Thanks,
Martin
Comment #15
quicksketchRegarding the PHP code option, I was responding to gunzip in #10 where he suggested a PHP field.
I don't really anticipate other modules modifying the list of URLs, but eh, you never know. If another module needs to add to this list, currently they can do so with code like the following:
But would point out this is now completely unnecessary to do anyway if you simply use URLs such as "something/add?name=%nid".
Comment #16
gunzip commented@M_z indeed i ended up using plain nodereference but loosing some of the cool features (reference link, read only field etc.) that nodereference_url provides.
Comment #17
m_z commented@gunzip:
You can try the new 1.4 release of Node Reference URL widget. It should work in your use case. There are configuration instructions in README.TXT.