Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save anonymous/db5ecb2e278d7055caf5 to your computer and use it in GitHub Desktop.
Save anonymous/db5ecb2e278d7055caf5 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using umbraco.cms.businesslogic.Tags;
using Umbraco.Forms.Core;
using Umbraco.Web;
namespace Contour.Addon.Tags
{
public class TagsPrevalueSourceType : FieldPreValueSourceType
{
[Umbraco.Forms.Core.Attributes.Setting("TagGroup",
description = "If you want to limit the tags by a specific group")]
public string TagGroup { get; set; }
public TagsPrevalueSourceType()
{
this.Id = new Guid("fa2b5315-d1e5-47a4-b6c0-3bc25c860c55");
this.Name = "List tags";
this.Description = "Uses the tags datatype as source";
}
public override List<PreValue> GetPreValues(Field field)
{
var l = new List<PreValue>();
var tags = new IEnumerable<Tag>();
if (string.IsNullOrEmpty(TagGroup))
tags = Tag.GetTags();
else
tags = Tag.GetTags(TagGroup);
int sort = 0;
foreach(var tag in tags)
{
PreValue pv = new PreValue();
pv.Id = tag.Id;
pv.Value = tag.TagCaption;
if (field != null)
{
pv.Field = field.Id;
}
pv.SortOrder = sort;
sort++;
rl.Add(pv);
}
return l;
}
public override List<Exception> ValidateSettings()
{
return new List<Exception>();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment