2

When duplicating an item in the content tree, a modal box appears to define the Name of the new item. From my experience, the text typed in this box is set as the Name of the new item.

However, I've recently saw instances identical to mine where the duplicate item had the same text as the original item in the content tree. The only difference being the text between brackets ([]) in the right panel. This is confusing to users as they are not sure which item to choose from the content tree.

The setup I am using is Sitecore 8.0 Update-5 + Launch Sitecore 8012 WebForms. This is the same setup on which I've seen the display name behavior.

What can explain this behavior of the duplicate item command?

EDIT/solution: I was confused between the Name and the Display Name at the time of asking the question. I edited the original question for clarity. It included the following sentence originally:

I've recently saw instances identical to mine where the name of the item stayed the same as the original item and the display name was set to what was entered in the dialog box.

It turns out the Name was really set to what the user entered in the dialog box. The name of the item is displayed between brackets in the right panel when selecting an item from the content tree. What was identical between the 2 items is really the Display Name, displayed in the content tree.

As you can see in the accepted answer, the reason for the different behavior is that I did not have a Display Name on the original item but the other people had one.

  • re: "However, I've recently saw instances identical to mine where the name of the item stayed the same as the original item and the display name was set to what was entered in the dialog box. This is confusing to users as they then have 2 items with the same name." -> Content Editor tree by default deplays the display name of an item if display name is present. – scFootsteps Nov 26 '16 at 15:56
  • This is not standard Sitecore behaviour nor LaunchSitecore (which has a custom item:saved event defined handler to remove spaces). Make sure there is not any custom code which might affect it. – jammykam Nov 27 '16 at 17:16
2

However, I've recently saw instances identical to mine where the name of the item stayed the same as the original item and the display name was set to what was entered in the dialog box. This is confusing to users as they then have 2 items with the same name.

from the above text you have mention in your question, what I understand was you are expecting Content Editor Tree should display the Name of the item. But, by default it is displaying the "Display Name" of the item if it exists.

for example, when I enter a display name to my home item, it will look like below

enter image description here

And when a duplicate item is created, the Name entry box value will be used as Item Name of new Item. "Display Name" of the new item will remain same.

enter image description here

Is that the issue you are taking about ??

  • 1
    I think you are right @scFootsteps. Your screenshots made me realize that the Sitecore instance which was behaving differently from mine is really displaying the "Display Name" in the content tree. The "Display Name" was the same for both items and the "Name" (between []) of the duplicate item was set to the text entered in the dialog box. In the end, the reason of the different behavior is because the user has set a "Display Name" on the item prior to duplicating it. – Jean-François L'Heureux Nov 27 '16 at 19:40
2

You can check it on item:copied and fix it. You can change the checks to meet your goals.

public class ItemEventHandler
{
    protected void SetNameToDisplayName(object sender, EventArgs args)
    {
        var copiedItem = (Item)Event.ExtractParameter(args, 1);

        if (copiedItem.Database.Name != "master"
            || !copiedItem.Paths.Path.StartsWith("/sitecore/content/")
            || copiedItem.Appearance.DisplayName == copiedItem.Name)
        {
            return;
        }

        copiedItem.Editing.BeginEdit();
        try
        {
            copiedItem.Appearance.DisplayName = copiedItem.Name;
        }
        finally
        {
            copiedItem.Editing.EndEdit();
        }
    }
}

Config

  <sitecore>
    <events>
      <event name="item:copied">
        <handler type="Sitecore.Foundation.Presentation.EventHandler.ItemEventHandler, Sitecore.Foundation.Presentation" method="SetNameToDisplayName">
          <patch:insert/>
        </handler>
      </event>
    </events>
  </sitecore>
  • Had to fix it a bit to handle the copied item. Different than creating an item. – Chris Auer Nov 25 '16 at 19:58
  • This looks like a solution to modify the default Sitecore behavior. My question was to understand the default Sitecore behavior and why 2 similar instances are behaving differently. – Jean-François L'Heureux Nov 25 '16 at 21:53
  • In the environments i testing to build that code, I have the same experience you have. Duplicating an item renames the item, but does not rename the Display Name. The code above gets around it. Let me test in an 8.1 environment. I tested in 8.2. – Chris Auer Nov 25 '16 at 22:11
  • I just verified that an out of the box 8.1 U3 and 8.2 both rename the item to the pop-up when copied. Very odd. So something in my test site is making me use the code above to rename the copied item to the pop up name. Let me keep digging. – Chris Auer Nov 25 '16 at 22:24
  • 1
    I was able to duplicate the issue with a single item in my test instance. But after an IISRESET it started acting normally. No errors, no logs to help identify the issue. Sorry. – Chris Auer Nov 26 '16 at 2:49

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.