How to extend the Content Editor

Hello,

In training materials it's shown a possibility to extend the editor:
https://community.telligent.com/community/11/w/developer-training/65057/extending-the-content-editor

I'm trying to do the same (at least to repeat the sample) without any success. Could you help to identify missings?

Extensions/Controllers/TextEditor.cs

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Telligent.DynamicConfiguration.Components;
using Telligent.Evolution.Extensibility.EmbeddableContent.Version1;
using Telligent.Evolution.Extensibility.Version1;

namespace Test.Extensions.Controllers
{
	public class TextEditor : IEmbeddableContentFragmentType, ITranslatablePlugin, IPlugin
	{
		readonly Guid _fragmentTypeId = new Guid("6c33babb0c0e45e8b691294b8b6569e5");

		ITranslatablePluginController _translation;

		#region IEmbeddableContentFragmentType Members
		public string ContentFragmentName
		{
			get { return _translation.GetLanguageResourceValue("fragment_name"); }
		}

		public string ContentFragmentDescription
		{
			get { return _translation.GetLanguageResourceValue("fragment_description"); }
		}

		public Guid EmbeddedContentFragmentTypeId
		{
			get { return _fragmentTypeId; }
		}

		public bool CanEmbed(Guid contentTypeId, int userId)
		{
			return true;
		}

		PropertyGroup[] IEmbeddableContentFragmentType.EmbedConfiguration
		{
			get
			{
				var group = new PropertyGroup("options", _translation.GetLanguageResourceValue("configuration_group"), 1);
				group.Properties.Add(new Property("color", _translation.GetLanguageResourceValue("configuration_color"), PropertyType.Color, 1, ""));
				return new PropertyGroup[] { group };
			}
		}

		void IEmbeddableContentFragmentType.AddUpdateContentFragments(Guid contentId, Guid contentTypeId, IEnumerable<IEmbeddableContentFragment> embeddedFragments)
		{

		}

		public string PreviewImageUrl
		{
			get { return null; }
		}

		string IEmbeddableContentFragmentType.Render(IEmbeddableContentFragment embeddedFragment, string target)
		{
			if (System.Diagnostics.Debugger.Launch()) System.Diagnostics.Debugger.Break();

			var color = embeddedFragment.GetString("color");

			if (String.IsNullOrEmpty(color))
				return String.Empty;

			return String.Format("<div style='height: 300px; width: 300px; background-color: {0};'> </div>", color);
		}

		EmbeddableContentFragmentValidationState IEmbeddableContentFragmentType.Validate(IEmbeddableContentFragment embeddedFragment)
		{
			if (System.Diagnostics.Debugger.Launch()) System.Diagnostics.Debugger.Break();

			var color = embeddedFragment.GetString("color");

			if (string.IsNullOrEmpty(color))
				return new EmbeddableContentFragmentValidationState(false) { Message = _translation.GetLanguageResourceValue("configuration_colorinvalid") };

			return new EmbeddableContentFragmentValidationState(true);
		}
		#endregion

		#region IPlugin Members
		string IPlugin.Description
		{
			get { return "Displays a box with configurable height."; }
		}

		void IPlugin.Initialize()
		{

		}

		string IPlugin.Name
		{
			get { return "Sample Embeddable"; }
		}
		#endregion

		#region ITranslatablePlugin Members
		Translation[] ITranslatablePlugin.DefaultTranslations
		{
			get
			{
				var translation = new Translation("en-us");

				translation.Set("fragment_name", "Embeddable Box");
				translation.Set("fragment_description", "Displays a box with configurable height.");

				translation.Set("configuration_group", "Options");
				translation.Set("configuration_color", "Background Color");
				translation.Set("configuration_colorinvalid", "A Background Color must be provided.");

				return new Translation[] { translation };
			}
		}

		void ITranslatablePlugin.SetController(ITranslatablePluginController controller)
		{
			_translation = controller;
		}
		#endregion
	}
}

	public class TextEditorExtension : IScriptedContentFragmentExtension
	{
		public string ExtensionName => "test_v1_text_editor";
		public string Name => "Text Editor";
		public string Description => "Text Editor";
		public object Extension => new TextEditor();
		public void Initialize() { }
	}



Changed class name
[edited by: Viachaslau at 2:47 PM (GMT 0) on Mon, Jul 27 2020]
Parents Reply Children
  • Former Member
    0 Former Member in reply to Viachaslau

    You can remove items from the Insert menu by turning off the plugins that define them.  You can add new items by create new IEmbeddableContentFragmentType and enabling their plugins. There are a few other options for the editor in Administration > Site > Editor Options.  Beyond that the other menus can not be modified.

  • Is it a correct initialization?

    #set ($siTextEditor = $core_v2_widget.UniqueId('siTextEditor'))
    
    <form>
        #set ($submittableEditorOptions = '%{}')
        $submittableEditorOptions.Add('Width','100%')
        $submittableEditorOptions.Add('Height','60px')
        $submittableEditorOptions.Add('SubmitLabel', $core_v2_language.GetResource('REPLY_BUTTON_NAME'))
        $submittableEditorOptions.Add('EnableEnterToSubmitToggle', false)
        $submittableEditorOptions.Add('AutoResize', true)
    [!]    $submittableEditorOptions.Add('ContentTypeId', $test_v2_custeditor.ContentTypeId.ToString())
        $core_v2_submittableEditor.Render($siTextEditor, 'createNewSSVCComment', $submittableEditorOptions)
    </form>

    Alternatively, possibly, dev. training sample can be downloaded for familiarization purposes, can't it ?

  • Former Member
    0 Former Member in reply to Viachaslau

    I am still not sure what you are trying to accomplish.  The source code of that sample is available near the end of the article, its labeled completed source code for the sample.

  • Possibly, my problem in trying to apply it for a proper section / page instead of a general update for the editor. The option did not appear in our editor, because we do not know how to add this filtering to the content type.