Article Hashtags

This interface provides #tag support for the content type. It provides a controller that gives access to several methods not available in the API.

Why should I make my content hashtaggable?

Similar to tags the hashtag allows users to provide keywords but it also provides an easy way to tag content inline.

Creating an IHashTaggableContentType plugin

The IHashTaggableContentType interface is defined in the Telligent.Evolution.Extensibility.Content.Version1 namespace of Telligent.Evolution.Core.dll. It also inherits from ITaggableContentType with one added method to set a controller.

It is important to note that one or more Core Services can be implemented in the same IContentType class.

The IHashTagController is used to bind the tag to the content, property name and html of your item. The controller should be used when creating and updating your content. For example _hashTagController.AddUpdateHashTags(content.ContentId, "Description", content.HtmlDescription("Raw")); this would create the appropriate tags for your content in the platform.

private IHashTagController _hashTagController;

public void SetController(IHashTagController controller)
{
    _hashTagController = controller;
}

Here is the full sample.

using System;
using System.Collections.Generic;
using System.Linq;
using Telligent.Evolution.Extensibility;
using Telligent.Evolution.Extensibility.Api.Version1;
using Telligent.Evolution.Extensibility.Content.Version1;
using IContent = Telligent.Evolution.Extensibility.Content.Version1.IContent;

namespace Samples.Links
{
    public class LinkItemContentType : IContentType, IHashTaggableContentType
    {
        IContentStateChanges _contentState = null;

        #region IPlugin Members

        public string Description
        {
            get { return "Items in a Links collection"; }
        }

        public void Initialize()
        {
        
        }

        public string Name
        {
            get { return "Link Items"; }
        }
        
        #endregion

        #region IContentType Members

        public Guid[] ApplicationTypes
        {
            get { return new Guid[] { ContentTypes.LinksApplicationId }; }
        }

        public void AttachChangeEvents(IContentStateChanges stateChanges)
        {
            _contentState = stateChanges;
        }

        public Guid ContentTypeId
        {
            get { return ContentTypes.LinksItemId; }
        }

        public string ContentTypeName
        {
            get { return "Links Item"; }
        }

        public IContent Get(Guid contentId)
        {
            return LinksData.GetLink(contentId);
        }

        #endregion

        #region ITaggableContentType

        public bool CanAddTags(Guid contentId, int userId)
        {
            var content = LinksData.GetLink(contentId) as IContent;
            if (content == null) { return false; }

            var modifyGroup = new Guid("C1E107FD-2046-4e15-9655-55D9BDE8CE70");
            var permission = Apis.Get<IPermissions>().Get(modifyGroup, userId, content.ContentId, content.ContentTypeId);

            return content.CreatedByUserId == userId || permission.IsAllowed;
        }

        public bool CanRemoveTags(Guid contentId, int userId)
        {
            var content = LinksData.GetLink(contentId) as IContent;
            if (content == null) { return false; }

            var modifyGroup = new Guid("C1E107FD-2046-4e15-9655-55D9BDE8CE70");
            var permission = Apis.Get<IPermissions>().Get(modifyGroup, userId, content.ContentId, content.ContentTypeId);

            return content.CreatedByUserId == userId || permission.IsAllowed;
        }

        #endregion

        #region IHashTaggableContentType

        private IHashTagController _hashTagController;

        public void SetController(IHashTagController controller)
        {
            _hashTagController = controller;
        }

        #endregion
    }
}