3

Is it possible to change the format shown in the Content Editor, of item version mode as "version 1", "version 2", etc rater than 1,2,3

2

If you want to have Version 1, Version 2,... , Version N in Content editor view is possible but I don't see any advantage to have it. I didn't change anything in the Sitecore database, I changed just the view from Content Editor.

I changed a bit the code to have "Version 1" instead to "1."

Please see below picture :

enter image description here

You need to make next changes :

Add a new class GalleryVersionsForm :

public class GalleryVersionsForm : GalleryForm
{
    /// <summary></summary>
    protected GalleryMenu Options;

    /// <summary></summary>
    protected Scrollbox Versions;

    /// <summary>
    /// Handles the message.
    /// </summary>
    /// <param name="message">The message.</param>
    public override void HandleMessage(Message message)
    {
        Assert.ArgumentNotNull(message, "message");
        if (message.Name == "event:click")
        {
            return;
        }
        base.Invoke(message, true);
    }

    /// <summary>
    /// Raises the load event.
    /// </summary>
    /// <param name="e">The <see cref="T:System.EventArgs" /> instance containing the event data.</param>
    /// <remarks>
    /// This method notifies the server control that it should perform actions common to each HTTP
    /// request for the page it is associated with, such as setting up a database query. At this
    /// stage in the page lifecycle, server controls in the hierarchy are created and initialized,
    /// view state is restored, and form controls reflect client-side data. Use the IsPostBack
    /// property to determine whether the page is being loaded in response to a client postback,
    /// or if it is being loaded and accessed for the first time.
    /// </remarks>
    protected override void OnLoad(EventArgs e)
    {
        Assert.ArgumentNotNull(e, "e");
        base.OnLoad(e);
        if (Context.ClientPage.IsEvent)
        {
            return;
        }
        Item currentItem = GalleryVersionsForm.GetCurrentItem();
        if (currentItem != null)
        {
            if (currentItem.IsFallback)
            {
                HtmlGenericControl htmlGenericControl = new HtmlGenericControl("div");
                htmlGenericControl.InnerText = Translate.Text("No version exists in the current language. You see a fallback version from '{0}' language.", new object[]
                {
                    currentItem.OriginalLanguage
                });
                htmlGenericControl.Attributes["class"] = "versionNumSelected";
                Context.ClientPage.AddControl(this.Versions, htmlGenericControl);
            }
            else
            {
                Item[] versions = currentItem.Versions.GetVersions();
                for (int i = versions.Length - 1; i >= 0; i--)
                {
                    Item item = versions[i];
                    XmlControl xmlControl = ControlFactory.GetControl("Gallery.Versions.Option") as XmlControl;
                    Assert.IsNotNull(xmlControl, typeof(XmlControl), "Xml Control \"{0}\" not found", new object[]
                    {
                        "Gallery.Versions.Option"
                    });
                    Context.ClientPage.AddControl(this.Versions, xmlControl);
                    CultureInfo culture = Context.User.Profile.Culture;
                    string text = (item.Statistics.Updated == DateTime.MinValue) ? Translate.Text("[Not set]") : DateUtil.FormatShortDateTime(DateUtil.ToServerTime(item.Statistics.Updated), culture);
                    string text2 = (item.Statistics.UpdatedBy.Length == 0) ? "-" : item.Statistics.UpdatedBy;
                    string text3 ="Version "+ item.Version + ".";
                    if (item.Version.Number == currentItem.Version.Number)
                    {
                        text3 = "<div class=\"versionNumSelected\">" + text3 + "</div>";
                    }
                    else
                    {
                        text3 = "<div class=\"versionNum\">" + text3 + "</div>";
                    }
                    xmlControl["Number"] = text3;
                    xmlControl["Header"] = Translate.Text("Modified <b>{0}</b> by <b>{1}</b>.", new object[]
                    {
                        text,
                        text2
                    });
                    xmlControl["Click"] = string.Format("item:load(id={0},language={1},version={2})", currentItem.ID, currentItem.Language, item.Version.Number);
                }
            }
        }
        Item item2 = Client.CoreDatabase.GetItem("/sitecore/content/Applications/Content Editor/Menues/Versions");
        if (item2 != null && item2.HasChildren)
        {
            string queryString = WebUtil.GetQueryString("id");
            this.Options.AddFromDataSource(item2, queryString, new CommandContext(currentItem));
        }
    }

    /// <summary>
    /// Gets the current item.
    /// </summary>
    /// <returns>The current item.</returns>
    private static Item GetCurrentItem()
    {
        string queryString = WebUtil.GetQueryString("db");
        string queryString2 = WebUtil.GetQueryString("id");
        Language language = Language.Parse(WebUtil.GetQueryString("la"));
        Sitecore.Data.Version version = Sitecore.Data.Version.Parse(WebUtil.GetQueryString("vs"));
        Database expr_3C = Factory.GetDatabase(queryString);
        Assert.IsNotNull(expr_3C, queryString);
        return expr_3C.Items[queryString2, language, version];
    }
    }

Above class is almost the same with class : Sitecore.Shell.Applications.ContentManager.Galleries.Versions.GalleryVersionsForm

Only one change is : string text3 ="Version " + item.Version + ".";

instead of string text3 = item.Version + ".";

To use your code you need to modify \Website\sitecore\shell\Applications\Content Manager\Galleries\Versions\Gallery Versions.xml .

You have to change Codebeside section to :

<CodeBeside Type="YourNamespace.GalleryVersionsForm,YourAssembly">
  • Thanks for the reply. Will implement this and shall confirm. – PVM Oct 5 '17 at 0:03
  • please mark it correct answer – Vlad Iobagiu Oct 6 '17 at 7:30
2

No it isn't

Sitecore treats Version internally as an integer. To change this behaviour would cascade changes all the way through the system, all the way down to database level.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.