This is needed when using both pathauto for node titles, and using a cck nodereferance field.
My primary computer is dead and I don't have a diff engine on the one I am borrowing, so I cannot make a true patch.
node.views.inc::views_plugin_argument_validate_node->validate_argument
case 'convert':
if($types) {
$and = " AND type IN ('" . implode("', '", $types) . "')";
}
$node = db_fetch_object(db_query("SELECT * from {node} WHERE title = '%s'$and", $argument));
if(!$node) {
return FALSE;
}
if (!empty($this->argument->options['validate_argument_node_access'])) {
if (!node_access('view', $node)) {
return FALSE;
}
}
$this->argument->validated_title = $node->title;
$this->argument->argument = $node->nid;
return TRUE;
And of course, add
'convert' => t('Node title converted to node ID'),
in 'validate_argument_nid_type' => '#options'
This just uses the first match found, but I could not think of a better way to do it. This is still needed for a site designed using the cck node reference field and aliased urls, however. Otherwise, the site's url pattern would need to be "projects/site", "projects/4/support", rather than using the project name at all urls.
Comments
Comment #1
RoboPhred commentedComment #2
merlinofchaos commentedSo I think this is a good idea, but I worry that it'll generate a lot of negative feedback:
1) nodes with the same title
2) nodes with titles that contain non URL-safe characters
I'll think on this one.
Comment #3
RoboPhred commentedCould my case be solved by using relationships? Somehow adding a node: title argument that reads the titles from the cck field?
I did notice that you can select a relationship for the argument to use, but did not really understand the actual relationship between them. I will poke at it a bit and see if that also solves this case.
Comment #4
RoboPhred commentedWow, the relationship setting is really powerful, now that I understand more of how they can be used. I thought they were just for getting access to new fields, not changing the target of old ones.
I was able to solve my case using them, so that is one mark down on the importance of this addition.
For the record, I did use non URL safe characters, they are converted to hex values and still function properly.
Comment #5
pkej commentedHi,
I added your patch and it is working well. As for duplicate titles it seems that auto node title creates unique paths for two nodes with the same title. It would therefore be possible to add the above code with the modification that it translates via the url path of pathauto instead.
Just an idea.
How did you do the things in #4 without the use of the title, please expand on it, I don't mind using a method which is safer.
Comment #6
RoboPhred commentedMy setup includes a "project" type, and a "feature" type that has a node cck field to select a "project" type.
To show all feature types for a project:
Add a relationship to the cck field you want to check.
Add an argument of "Node: Title" that uses the above relationship.
This will make it only show if the title of the node that is pointed to by the cck field matches the argument.
Comment #7
milkmug commentedI stumbled over your patch and applied it to my current project. But it didnt work.
My setup:
* 2 node types (A,B)
* node B contains a CCK field node reference to A
* pathauto of node B : [field_ref_descr_gi-title]/[title-raw].html which results to: <title-of-A>/<title-of-B>.html
My assumption: Since the argument is the converted and URL-usable title, it does'nt match the real title of the node.
(ref. line 6 of your code above)
my quick solution was to modify your patch as follows:
I know this is a quick and dirty hack, but I want to share it maybe it can be used for further development.
I wanted to dig deeper, but time's running out before Christmas (everyone want's his/her project finished)
Comment #8
merlinofchaos commentedNeed an actual patch to really review this. Also this issue is very old.
Comment #9
orbmantell commentedI am trying to do this exact same thing. I am making a photo gallery where the gallery is a content type "gallery" and the individual pictures are content type "picture" with a node reference CCK field pointing the the gallery node they are part of. I am trying to create a new tab on the gallery page to allow the re-ordering of the pictures (using the weight module), but because I am using pathauto to make my URLs nice I am running into issues. My gallery paths are gallery/[gallery title], and no matter what I try I cannot get the page view (with menu tab path of gallery/%/arrange) to show up. If I navigate to gallery/[node ID number]/arrange the view shows, but I cannot get it to work with the url alias.
Sorry if my description is unclear, let me know and I will try to describe what I am doing better.
Any help is appreciated, thanks.
~orbmantell
Comment #10
dboune commentedHere is a patch that does what the OP's code desired, and a little more, allowing for use of Node: Title (or another field) as well.
When used as an argument against node title, this patch supports urls with or without spaces when used along with the "Transform spaces to dashes in URL" option. This mirrors how it already works without this argument validator, but adds a properly formatted title as well as offering the rest of the validation features.
As the Transform option is not available for the nid field, you can only use exact (more or less) title matches.
I'm placing this patch here in the hopes that someone else may think further on the subject.
From my perspective this clearly needs more work.
Comment #11
dawehnerThis is undrupal-ish codestyle, sorry.
Comment #12
dboune commentedMy most sincere apologies. Can you point me to some drupalish codestyle of that nature? I would be happy to modify it.
Edit: I noted the exceptionally poor indenting.. not sure where I was at that moment. If it was just the indenting, I'll gladly upload a fixed version. If it was something about the actual code content of the conditional statement (non-formatting) I'd like to understand.
Comment #13
dawehnera identing and b)
Comment #14
dboune commentedUnderstood and fixed + a little more cleanup, thank you for pointing that out.
Comment #15
dawehneradditional this should be if () {
FROM
, too
Powered by Dreditor.
Sorry
Comment #16
dboune commentedThanks again, and sorry for that. Fixes made.
Comment #17
luckysmack commentedHas there been any kind of update for this? this is a feature I currently need for views. I need the user to be able to enter the nodes title (from a node reference field) rather than the node id.
Comment #18
dboune commentedHi luckysmack, I doubt we will see this particular ticket progress. I've worked this idea out a number of times, and like merlinofchaos originally said, there are just too many issues with using node titles in this way.
You might look at the node reference field issue from a different angle. There might be a way to design a node reference field that could allow a search by title, display those nodes along with specific node numbers, and allow the user to choose from them somehow. It would still have to store the node id as the reference.
Comment #19
mustanggb commented