Configuring Sitecore Ribbon Spellcheck
Suppose you want to spell check all fields on an item using the button you see below
If you tried it, you might have noticed that the spell checker doesn’t check single-line texts by default. I will show the quick and dirty way to configure this spellcheck to spellcheck whatever field types you want.
If we navigate to /sitecore/content/Applications/Content Editor/Ribbons/Chunks/Proofing/Spellcheck in your core database, we can see that on Click, the content editor executes the contenteditor:spellcheck command.
Looking at the \App_Config\Commands.config, you will find the following command with that name:
If we decompile the type Sitecore.Shell.Applications.ContentManager.Commands.Spellcheck,Sitecore.Client, we can see the following code:
The switch statement at line 36 lists all the field types which the spell checker will check. We can modify it to include or exclude whatever field type we want. In this example, I am including the another case for the single-line text field type:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using Sitecore;
using Sitecore.Data.Items;
using Sitecore.Diagnostics;
using Sitecore.IO;
using Sitecore.Shell.Framework.Commands;
using Sitecore.Text;
using Sitecore.Web.UI.HtmlControls;
using Sitecore.Web.UI.Sheer;
using System;
using System.Collections;
using System.IO;
using System.Web;
namespace MyLibrary.CustomSitecore.Commands
{
[Serializable]
public class Spellcheck : Command
{
public override void Execute(CommandContext context)
{
Assert.ArgumentNotNull(context, "context");
string dictionary = GetDataContext().Language.GetDictionary
(Context.ContentDatabase);
string str2 =
"/sitecore/shell/controls/rich text editor/Dictionaries/";
str2 = FileUtil.MakePath(FileUtil.MapPath(
Path.Combine(HttpContext.Current.Request.ApplicationPath, str2)),
dictionary);
if ((dictionary.Length == 0) || !FileUtil.Exists(str2))
{
SheerResponse.Alert(
"There is no spell checker dictionary for this language.",
new string[0]);
}
else
{
ListString str3 = new ListString();
foreach (Sitecore.Shell.Applications.ContentManager.FieldInfo info
in this.FieldInfo.Values)
{
switch (info.Type)
{
case "text":
case "memo":
case "multi-line text":
case "html":
case "rich text":
case "single-line text":
str3.Add(info.ID);
break;
}
}
SheerResponse.Eval(string.Concat(
new object[] { "StartSpellCheck(\"", str3, "\", \"",
Path.GetFileNameWithoutExtension(dictionary), "\")" }));
}
}
private static DataContext GetDataContext()
{
return Assert.ResultNotNull(
Context.ClientPage.FindSubControl("ContentEditorDataContext")
as DataContext);
}
public override CommandState QueryState(CommandContext context)
{
Assert.ArgumentNotNull(context, "context");
if (context.Items.Length != 1)
{
return CommandState.Hidden;
}
Item item = context.Items[0];
if (item.Appearance.ReadOnly)
{
return CommandState.Disabled;
}
if (!item.Access.CanWrite())
{
return CommandState.Disabled;
}
return base.QueryState(context);
}
public Hashtable FieldInfo
{
get
{
Hashtable hashtable =
Context.ClientPage.ServerProperties["Info"] as Hashtable;
if (hashtable == null)
{
hashtable = new Hashtable(5);
Context.ClientPage.ServerProperties["Info"] = hashtable;
}
return hashtable;
}
}
}
}