Skip to content

Instantly share code, notes, and snippets.

@TimGeyssens
Created February 18, 2015 11:19
Show Gist options
  • Save TimGeyssens/d4c7ef7920303e7a96f6 to your computer and use it in GitHub Desktop.
Save TimGeyssens/d4c7ef7920303e7a96f6 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.interfaces;
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 List<Tag>();
if (string.IsNullOrEmpty(TagGroup))
tags = Tag.GetTags().ToList();
else
tags = Tag.GetTags(TagGroup).ToList();
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++;
l.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