I'm struggling to get my language dropdown to work, which had worked prior to switching to RelationServices in 6.1. Anyway, I have now upgraded to 7.0.3 and my code is no longer working.
The idea behind this code is to switch between the language relations on any level of the tree. If a relation is not available then it should link to the language root.
Here is a picture of my top level, I have 3 language roots: de (german), fr (French) and it (Italian) and all was related on copy. As I want to be able to manually format and name the languages (not using the default Culture info), I have created a Property "Language" on each root.
If I understand what you're trying to achieve I'm not entirely sure whether you even need a relation as you could easily achieve what it looks like you are trying to do using a simple content query?
That said, have you checked the umbracoRelation table to see if the relations you are expecting to see do actually exist? If it does then can you check that your relations variable contains results? My question would be to then check that you have the parentId and childId are not the reverse of what you are checking against e.g. your parent is not in fact the child and vice versa.
Thanks for your support. This helped me narrow down the problem. Yes, there was data in the tables umbracoRelation and umbracoRelationType. Different than in your example I had to use IRelationService and IRelation, has this changed since you documented this?
Now this line is returning the correct values: IEnumerable<IRelation> relations = rs.GetByParentOrChildId((int)Model.Id).Where(r => r.RelationTypeId == 1);
However it won't work with the Alias name strangely enough, however I can use the Id instead.
My main diffultity I have now if the following statment is no longer looping through my level 1 nodes. Any ideas?
RelationService and Relation implement IRelationService and IRelation respectively, there should be nothing wrong with either approach. I've had a chance to review again and I can now see the issue with your original code.
The method signature for .GetAllRelations is as follows:
.GetAllRelations(params int[] ids)
You are passing the Id of your Model in but the method requires an array of relation object id's and explains why you get no results. What you actually want to do is get all relations for your object using one of the following methods...
.GetByParentId(int id)
Gets an enumerable list of Relation objects that have the specified ParentId.
.GetByChildId(int id)
Gets an enumerable list of Relation objects that have the specified ChildId.
.GetByParentOrChildId(int id)
Gets an enumerable list of Relation objects that have the specified ParentId or ChildId.
...then filter based on the relationtype alias using the Where clause, something like this:
Many thanks for your help. My last post contained a copy paste error, in my original post the line of code had the correct spacing, so hence this is not the issue.
My impression is that the following code no longer works in the current version, but I cannot find an example on how to get it working in the new version:
DynamicNode contentRoot = new DynamicNode(-1); @foreach(DynamicNode LanguageRoots in contentRoot.Descendants("LanguageTopFolder")) { do something }
Thanks for your help with the relations: This works:
Have you looked at the contents of contentRoot.Descendants()? Do you see the nodes you expect?
Did you also check the casing of the document type alias?
My suggestion is also to inspect the contents of rs.GetByParentId((int)Model.Id) and check the alias against the node you are expecting to be returned.
Just a thought, has there been a change in using double quotes?
Double quotes are not an Umbraco thing (specifically) they are used in .Net to declare a string.
Okay I inspected rs.GetByParentId((int)Model.Id) and first I just received timeouts, then suddenly it started working and I was able to see the RelationType.Alias. I have changed it back & it is now working.
Do you or does anyone else know what is the best way to access the true root? I need to be able to loop for all possible languages and this is generic code I want to use on all websites, hence it must be independant of the tree structure.
I wasn't aware of any issues getting the content root, I'd need to check on that however you could just as easily get all nodes at level 1 using the .GetByLevel(1) method on the ContentService.
Please make sure to vote up any answers you find useful and also the final solution :)
Thanks again for your help. The RelationService is fully functioning with your help.
The following code appears to be working for me:
var contentRoot = umbracoHelper.TypedContentAtRoot().ToList(); @foreach (var LanguageRoots in contentRoot) { do something }
However I have not managed to figure out why on some pages the language picker works and on others it doesn't. I hope to spend some time this weekend to further analyse this strange behaviour.
On some pages I get: "Error loading MacroEngine script (file: LanguageSelector.cshtml)". I'll debug some more and try to find out what is going on.
Language Dropdown Help Required Umbraco 7.0.3
Hi there
I'm struggling to get my language dropdown to work, which had worked prior to switching to RelationServices in 6.1. Anyway, I have now upgraded to 7.0.3 and my code is no longer working.
The idea behind this code is to switch between the language relations on any level of the tree. If a relation is not available then it should link to the language root.
Please help. The Relations and the DynamicNodes are no longer working. Any ideas?
Here is a picture of my top level, I have 3 language roots: de (german), fr (French) and it (Italian) and all was related on copy. As I want to be able to manually format and name the languages (not using the default Culture info), I have created a Property "Language" on each root.
The dropdown appears with the text: Undefined
If I understand what you're trying to achieve I'm not entirely sure whether you even need a relation as you could easily achieve what it looks like you are trying to do using a simple content query?
That said, have you checked the
umbracoRelation
table to see if the relations you are expecting to see do actually exist? If it does then can you check that yourrelations
variable contains results? My question would be to then check that you have theparentId
andchildId
are not the reverse of what you are checking against e.g. your parent is not in fact the child and vice versa.Simon
Hi Simon
Thanks for your support. This helped me narrow down the problem. Yes, there was data in the tables umbracoRelation and umbracoRelationType. Different than in your example I had to use IRelationService and IRelation, has this changed since you documented this?
Now this line is returning the correct values:
IEnumerable<IRelation> relations = rs.GetByParentOrChildId((int)Model.Id).Where(r => r.RelationTypeId == 1);
However it won't work with the Alias name strangely enough, however I can use the Id instead.
My main diffultity I have now if the following statment is no longer looping through my level 1 nodes. Any ideas?
Best regards
RelationService
andRelation
implementIRelationService
andIRelation
respectively, there should be nothing wrong with either approach. I've had a chance to review again and I can now see the issue with your original code.The method signature for
.GetAllRelations
is as follows:.GetAllRelations(params int[] ids)
You are passing the Id of your Model in but the method requires an array of relation object id's and explains why you get no results. What you actually want to do is get all relations for your object using one of the following methods...
.GetByParentId(int id)
Gets an enumerable list of Relation objects that have the specified ParentId..GetByChildId(int id)
Gets an enumerable list of Relation objects that have the specified ChildId..GetByParentOrChildId(int id)
Gets an enumerable list of Relation objects that have the specified ParentId or ChildId....then filter based on the relationtype alias using the
Where
clause, something like this:You are missing space in the code you posted which should be:
Also make sure your document type alias is not languageTopFolder (lower case 'l').
I hope that helps?
Simon
Hi Simon
Many thanks for your help. My last post contained a copy paste error, in my original post the line of code had the correct spacing, so hence this is not the issue.
My impression is that the following code no longer works in the current version, but I cannot find an example on how to get it working in the new version:
Thanks for your help with the relations:
This works:
yet this doesn't work:
I have checked in the UmbracoRelationType table and I have 1 entry: Id = 1, Alias = relateDocumentOnCopy
so I really don't understand why the Alias Lambda expression doesn't work.
Any ideas on these 2 issues? Just a thought, has there been a change in using double quotes?
Cheers
Jonathan
Have you looked at the contents of
contentRoot.Descendants()
? Do you see the nodes you expect? Did you also check the casing of the document type alias?My suggestion is also to inspect the contents of
rs.GetByParentId((int)Model.Id)
and check the alias against the node you are expecting to be returned.Double quotes are not an Umbraco thing (specifically) they are used in .Net to declare a string.
Simon
Hi Simon
Okay I inspected
rs.GetByParentId((int)Model.Id)
and first I just received timeouts, then suddenly it started working and I was able to see the RelationType.Alias. I have changed it back & it is now working.Regarding the other issue, there appears to be a lot of people with the same issue:
http://our.umbraco.org/forum/developers/api-questions/47125-How-to-get-the-root-node-in-Umbraco-67
Do you or does anyone else know what is the best way to access the true root? I need to be able to loop for all possible languages and this is generic code I want to use on all websites, hence it must be independant of the tree structure.
Many thanks
Jonathan
I wasn't aware of any issues getting the content root, I'd need to check on that however you could just as easily get all nodes at level 1 using the
.GetByLevel(1)
method on the ContentService.Please make sure to vote up any answers you find useful and also the final solution :)
Hi Simon
Thanks again for your help. The RelationService is fully functioning with your help.
The following code appears to be working for me:
However I have not managed to figure out why on some pages the language picker works and on others it doesn't. I hope to spend some time this weekend to further analyse this strange behaviour.
On some pages I get: "Error loading MacroEngine script (file: LanguageSelector.cshtml)". I'll debug some more and try to find out what is going on.
Cheers
Jonathan
is working on a reply...