Reputation: 4254
As an Umbraco developer, I am fairly new to Sitecore and so far have been fairly annoyed that some of the functionality that can easily be added in manually in Umbraco seems to be extremely convoluted and poorly documented in Sitecore.
Essentially, I have multiple language sites:
Beneath each of these sites are a set of articles:
English
- Article 1
- Article 2
French
- Article 3
- Article 4
What I want to achieve is a property in the back end that is categorised by country and allows the user to select multiple articles from across different language sites.
So, for example, I could select Article 1 and Article 3. Ideally the select control would look something like this with the countries as bold, unselectable categories and the options beneath being subject to standard multi-select behaviour.
Is anyone aware of how this may be achieved in Sitecore? Alternatively does anyone know of any Sitecore marketplace plugins that would allow me to achieve this as, so far, the documentation and literature on the web regarding this has been lacking.
Any help or pointers would be greatly appreciated.
Upvotes: 1
Views: 675
Reputation: 1445
I can get you most of the way there with a coded data source. If you create a class that inherits from IDataSource, you can fit it with whatever you want. What I can't get you is denying the user selecting the the bold countries.
Here is an article from John West talking about it and the code below is code I am currently using. I am using this code in a rendering property, so you will see many references to renderings. But all you are looking for is to return an array of Items.
Then in the datasource, you specify the word "code:" followed by you class name "," the assembly name.
code:Sitecore.Sharedsource.Data.FieldSources.CustomFieldDataSource,Sitecore.Sharedsource
public class GetStyles : IDataSource
{
public Item[] ListQuery(Item item)
{
bool flag = !string.IsNullOrWhiteSpace(Context.RawUrl) && Context.RawUrl.Contains("hdl");
if (flag)
{
string renderingId = FieldEditorOptions.Parse(new UrlString(Context.RawUrl)).Parameters["rendering"];
if (!string.IsNullOrEmpty(renderingId))
{
ItemUri renderingItemUri = new ItemUri(renderingId);
var containers = DependencyResolver.Current.GetService<IPresentationRepository>().GetStylesItem(renderingItemUri.ItemID, item);
if (containers == null)
return new Item[0];
return containers.Children.ToArray<Item>();
}
}
var result = new Item[0];
return result;
}
}
Upvotes: 0
Reputation: 2635
You can achieve something like that with a TreeList. It will look like a tree, so not exactly as you wanted but the functionality that you need can be done. The TreeList can be tweaked with the "source" value to show a part of the Sitecore tree, have certain items unselectable, and so on..
A good resource can be found here.
In your case, use the Datascource
and ExcludeTemplatesForSelection/IncludeTemplatesForSelection
options for the source query.
Upvotes: 2