Skip to main content
added 55 characters in body
Source Link
Chris Auer
  • 13.2k
  • 1
  • 30
  • 87

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

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

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

        itemcopiedItem.Editing.BeginEdit();
        try
        {
            itemcopiedItem.NameAppearance.DisplayName = item.AppearancecopiedItem.DisplayName;Name;
        }
        finally
        {
            itemcopiedItem.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>

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

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

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

        item.Editing.BeginEdit();
        try
        {
            item.Name = item.Appearance.DisplayName;
        }
        finally
        {
            item.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>

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>
added 1 character in body
Source Link
Chris Auer
  • 13.2k
  • 1
  • 30
  • 87

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

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

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

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

Config

  <sitecore>
    <events>
      <event name="item:added">copied">
        <handler type="Sitecore.Foundation.Presentation.EventHandler.ItemEventHandler, Sitecore.Foundation.Presentation" method="SetNameToDisplayName">
          <patch:insert/>
        </handler>
      </event>
    </events>
  </sitecore>

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

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

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

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

Config

  <sitecore>
    <events>
      <event name="item:added">
        <handler type="Sitecore.Foundation.Presentation.EventHandler.ItemEventHandler, Sitecore.Foundation.Presentation" method="SetNameToDisplayName">
          <patch:insert/>
        </handler>
      </event>
    </events>
  </sitecore>

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

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

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

        item.Editing.BeginEdit();
        try
        {
            item.Name = item.Appearance.DisplayName;
        }
        finally
        {
            item.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>
Source Link
Chris Auer
  • 13.2k
  • 1
  • 30
  • 87

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

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

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

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

Config

  <sitecore>
    <events>
      <event name="item:added">
        <handler type="Sitecore.Foundation.Presentation.EventHandler.ItemEventHandler, Sitecore.Foundation.Presentation" method="SetNameToDisplayName">
          <patch:insert/>
        </handler>
      </event>
    </events>
  </sitecore>