This is a really specific problem that occurs on sites with multiple languages and cck nodereferences.
When you use the node service to save a node that has a nodereference and is in a different language than the default language, you get an error.
I came across this problem by using the deployment module.
Both sites have two languages, dutch and french. With dutch as the default language.
When I deployed a french node with a node reference to an other french node it failed with the error:
%name: this post can't be referenced.
This error is generated by nodereference_field in nodereference.module
It generates a list of possible nodereferences (_nodereference_potential_references)
by executing the query
SELECT DISTINCT n.nid, n.title AS node_title, n.type AS node_type
FROM {node} n
WHERE (n.language ='nl' OR n.language ='' OR n.language IS NULL)
AND ( (n.type = '%s' OR n.type = '%s')
AND (n.nid IN (%d)) )ORDER BY n.title, n.type
In the first WHERE part the current language is used. In this case dutch: (n.language ='nl' OR n.language ='' OR n.language IS NULL)
But because the referenced node is in french, no results are found. This results in the error.
I think it is better to set the current active language to the language of the node that is going to be saved.
So I added
global $language;
$languages = language_list();
$language = isset($languages[$edit['language']]) ? $languages[$edit['language']] : $language;
to node_service_save. This solved the problem.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | services-956848.patch | 825 bytes | johannesdr |
| #8 | services-956848.patch | 616 bytes | johannesdr |
| #5 | services-956848_0.patch | 643 bytes | wmostrey |
| #3 | services-956848.patch | 643 bytes | johannesdr |
| #1 | services-956848.patch | 647 bytes | johannesdr |
Comments
Comment #1
johannesdr commentedHere is a patch for my suggested change.
Comment #3
johannesdr commentedRemoved windows formatting
Comment #5
wmostrey commentedRe-upload.
Comment #6
wmostrey commentedComment #8
johannesdr commentedre-upload, changed patch path
Comment #10
johannesdr commentedre-upload
Comment #11
johannesdr commentedComment #12
wmostrey commentedPassed the last test and I can confirm it to work as advertised.
Comment #13
kylebrowning commentedThanks!