Hello there,
I did a lots of RTFM on docs and issues in many CCK projects (in this project, mostly) for about a solution to get node nid at least in PHP codes on any fields in editing time, but no solution found by me. Computed Field not plays for me. The original problem described below, then my solution after:
I'm using Node Hierarchy and 3 content types in this context of the problem.
- A "project" content, which can have "release" and "issue" children (real or fact children).
- A "release" content, which points to "project" with a node reference.
- An "issue" content, which is a child of "project" by node hierarchy.
I wanted to get a checkbox list when create/edit an issue, which contains all available releases what the parent project have.
1.) With a computed field, i can get the node id, but cannot do a display of checkbox list.
2.) With an other field (not a computed) there's no chance for get the node's id (if creating, parent id in the URL, if editing, parent id in node's data).
3.) Not found a solution for exchanging data between a computed field and another field, because other fields do not have a solution for getting outside extra informations.
So, I made a hack in content.module's (v6.x-2.1, $id 1.301.2.85 2008/11/10 15:5635) content_load() function's line 2 (in file, this is #235) - inserted a row: $GLOBALS['_cck_nid'] = $node->nid;
Now if I need the actually edited node's id, I do only this in possible values PHP: global $_cck_nid;
Any better ideas are welcome - or if there are not, I think the actual nid is a really primitive data information in all fields' life, so any chance to implement a solution for this problem in the next versions will welcome too.
Thanx anyway!
Comments
Comment #1
markus_petrux commentedIn the node edit form, the node id is the second argument of the path, so you can get it using
$nid = arg(1).http://api.drupal.org/api/function/arg/6
Comment #2
prom3theus commentedHello and thanks for responding :)
It's really a bit nicer than mine what you wrote, but - and I studiously says that is not my problem, but maybe the others' - what about if have editablefields module enabled on a path aliased node? I think, in this case, content_load() called and in my "solution" $_cck_nid have real NID, but if the node accessed on "/omg/foo/bar" and not on "node/32", the arg(1) returns "foo"... Is this think have any truth or I missed something on arg's working? ^^
Regards.
Comment #3
markus_petrux commentedWhen Drupal bootstraps, one of the phases is DRUPAL_BOOTSTRAP_PATH, and that invokes drupal_init_path(), and that fixes $_GET['q'] with the 'normal' path. If there were a path alias, it would get fixed at that point. So arg() should be good enough to give you the proper nid.