Showing posts with label RTE. Show all posts
Showing posts with label RTE. Show all posts

Monday, April 05, 2010

Sitecore Rich Text Field - Iframe gotcha


If you ever tried putting an iframe in the Rich Text Field, you probably got what I got:

Server Error in '/' Application.
Empty strings are not allowed.
Parameter name: name

To solve this you have at least two options:
1. Wrap your iframe with the xsl:template definition. This way the iframe will appear as a web control in the rich text editor, but will render fine on the content delivery.
<xsl:template match="*" mode="main">
     <iframe id="iframe" src="..."></iframe>
</xsl:template>

2. Turn off HtmlEditor.SupportWebControls setting in web.config:
<setting name="HtmlEditor.SupportWebControls" value="false"/>

The second option makes more sense since you don’t need to alter the rich text content. If you don’t paste webcontrols to the rich text field, go for it.

Tuesday, March 09, 2010

Read only view of Rich Text field for Sitecore editor


Today I want to share an idea of a lightweight customization for Sitecore CMS that meant to increase usability of the rich text field for your editors. The idea is inspired by great feedback I received recently while being in the field.

The basic problem reported by one of the editors who uses Sitecore on the daily basis, is that when a content item is approved in workflow there is no way to see what’s inside of a rich text field easily. All field buttons are grayed out thus disabled:
disabled rich text field
…so the only way is to click “Lock and Edit” which creates a new version:
lock-and-edit

As you can imagine, this is not generally acceptable. If your non-admin editor user simply wants to see what’s in there, you don’t want a new version to be created.

Now it is worth mentioning that the item which is approved, unlocked is disabled for editing only if “RequireLockBeforeEditing” setting is set to true which is often the case, since you would want to have “Lock and Edit” in place so new version of the approved content is created.

Same goes along with the items that are locked. If there is a locked item, I would still want to see the content of the rich text field in read-only mode.

So one of the easiest ways I could think of to address this was enable “preview” of the rich text field in a modal dialog on double click.

Tech support provided the following solution which enabled the double click on disabled rich text field and showed the “preview” version of the field in a modal dialog:image

To make it work, follow these steps:
1. Open Preview.aspx under /sitecore/shell/Controls/Rich Text Editor.
2. Locate the scEdit() function and comment out the first IF statement:

function scEdit() {
        //if (scDisabled == "1") {
         // return;
       // }
        
var form = scGetForm();
...

3. Compile the following code:

namespace Company.Web.Fields
{
   using Sitecore.Diagnostics;
   using Sitecore.Shell.Applications.ContentEditor.RichTextEditor;
   using Sitecore.Web.UI.Sheer;

   public class RichText : Sitecore.Shell.Applications.ContentEditor.RichText
   {
      protected new void EditText(ClientPipelineArgs args)
      {
         Assert.ArgumentNotNull(args, "args");
         if (Disabled && !args.IsPostBack)
         {
            var url = new RichTextEditorUrl
                         {
                            Conversion = RichTextEditorUrl.HtmlConversion.Runtime,
                            Disabled = Disabled,
                            FieldID = FieldID,
                            ID = ID,
                            ItemID = ItemID,
                            Language = ItemLanguage,
                            Mode = string.Empty,
                            Source = Source,
                            Url = "/sitecore/shell/Controls/Rich Text Editor/Preview.aspx",
                            Value = Value,
                            Version = ItemVersion
                         };

            var str = url.GetUrl();
            SheerResponse.ShowModalDialog(str.ToString(), "800px", "500px", string.Empty, true);
            args.WaitForPostBack();
         }

         base.EditText(args);
      }
   }
}

4. In web.config, add your own controlSource reference to the namespace above:

<controlSources>
      <source mode="on" namespace="Sitecore.Web.UI.XmlControls" folder="/sitecore/shell/override" deep="true" />
...
       <source mode="on" namespace="Company.Web.Fields" assembly=" Company.Web" prefix="custom" />
</controlSources>

5. In the core database, locate the Rich Text field item (/sitecore/system/Field types/Simple Types/Rich Text) and adjust the value of the “control” field:
custom:RichText
Note that the prefix is used from the controlSource reference above.

Simple and lightweight customization that should bring some value. Sitecore rocks!

Tested on 6.1, expected to work on 6.0.x and 6.2.

Wednesday, February 24, 2010

Insert Media Item dialog in rich text field – remember last selection


Just last week I was at a customer talking to end users, authors who use the Sitecore CMS every day. It was was a very productive session, some quite valuable feedback was gathered.

One of the reported inconveniences with the rich text editor was inability for the “Insert Media Item” dialog to remember the previously selected location. It always falls back to the media library root when opened.
Insert Media Item - new

With active  content entry, especially media related, this dialog is used quite often.
Plus as the media library grows significantly, it takes more time to browse through the media library structure to locate the much needed media.

Thanks to Sitecore’s customizability, you can easily change that. By simply overriding the InsertImage XML control with new code that remembers the previous location.

namespace SCUSAINC.Shell.Applications.Dialogs
{
   using System;
   using Sitecore;
   using Sitecore.IO;
   using Sitecore.Data.Items;
   using Sitecore.Data;
   using Sitecore.Resources.Media;
   using Sitecore.Diagnostics;

   class InsertImageForm : Sitecore.Shell.Controls.RichTextEditor.InsertImage.InsertImageForm
   {
      protected override void OnLoad(EventArgs e)
      {
         Assert.ArgumentNotNull(e, "e");
         if (!Context.ClientPage.IsEvent)
         {
            var prevMedia = Context.ClientPage.Session["prevMedia"];
            DataContext.GetFromQueryString();
            Item folder;
            if (prevMedia != null)
            {
               folder = Context.ContentDatabase.GetItem(ID.Parse(prevMedia.ToString()));
               if (folder != null)
               {
                  DataContext.SetFolder(folder.Uri);
               }
            }
         }
         base.OnLoad(e);
      }

      protected override void OnOK(object sender, EventArgs args)
      {
         base.OnOK(sender, args);

         var filename = Filename.Value;
         if (filename.Length != 0)
         {
            var root = DataContext.GetRoot();
            if ((root != null) && (root.ID != root.Database.GetRootItem().ID))
            {
               filename = FileUtil.MakePath(root.Paths.Path, filename, '/');
            }
            MediaItem item = DataContext.GetItem(filename);
            if ((item != null) && ((MediaManager.GetMedia(MediaUri.Parse(item)) is ImageMedia)))
            {
               Context.ClientPage.Session.Add("prevMedia", item.ID.ToString());
            }
         }
      }
   }
}

After the code is compiled, you will need to copy the source file of the InsertImage XML control that can be found here: \sitecore\shell\Controls\Rich Text Editor\InsertImage\ to the \sitecore\shell\Override\ folder and make the following change:

<CodeBeside Type="SCUSAINC.Shell.Applications.Dialogs.InsertImageForm,SCUSAINC"/>

Huge thanks goes to Kirill T from the customer service for the solution!

Related reading:
http://sdn.sitecore.net/Scrapbook/Customize%20an%20XML%20Control.aspx

Enjoy and please do share if you like it! ;-)

Friday, October 30, 2009

Quick tip – remove “Edit HTML” option for the rich text field


A while ago  (in 2005 actually), I blogged about how to disable HTML tab in the HTML Editor. How it is almost 2010 and it is time to post an update :-)
Well, first thing I would like to point out is that after 4+ years, the approach pretty much has not changed. We changed the rich text editor from CuteEditor to Telerik’s RAD Editor, released a great deal of new functionality, but still preserved the idea of backward compatibility even in such small things as rich text editor configuration!
Isn’t it amazing?

Enough reminiscing, let me cut to the chase! Today with 6.x, you can still disable HTML tab for the RTE by modifying the security permissions on the “HTML View” item in one of the rich text profiles, for example for the “Rich Text Full”: /sitecore/system/Settings/Html Editor Profiles/Rich Text Full/Buttons/HTML View

Two things changed here. All profile definitions migrated to the “core” database and now the container names are a bit different.

In addition to this, as one of our partners noticed, there is another button in Content Editor above the RTE field called “Edit HTML” which needs to have the same rules applied to.
Capture

For that, follow the following steps:
1. Go to the core database, locate the field definition item:
/sitecore/system/Field types/Simple Types/Rich Text/Menu/Edit Html
2. On the Security Tab, click “Assign” and select the role you don’t want this option to be available to. Deny inheritance of this item or specify other security settings that make sense for your needs.
inheritance

That’s it, Folks! Enjoy Sitecore!