November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Hi Alfredo,
I'm not sure I understand your question. Could you be a bit more specific?
Sure, I have block type class like this:
using System.ComponentModel.DataAnnotations;
<pre> using System.ComponentModel.DataAnnotations; using EPiServer.Core; using EPiServer.DataAbstraction; using EPiServer.DataAnnotations; using EPiServer.Web; using EPiServer; using NextGen.CMS.Models.Media; using EPiServer.Shell.ObjectEditing; using EPiServer.ServiceLocation; using System; namespace NextGen.CMS.Models.Blocks.Silverpop { [ContentType(DisplayName = "Blog Offer Type Block" , GUID = "a7a0a0a7-e644-447b-9605-6996b387f89d" , GroupName = "Silverpop Offer Types" , Description = "The widget displays a blog offer.")] public class BlogOfferBlock : ContentData { /// <summary> /// Gets or sets ProductInterestType. /// </summary> /// <value> /// ProductInterestType. /// </value> [Display( Name = "Product Interest", Description = "Product Interest", GroupName = SystemTabNames.PageHeader, Order = 101)] [SelectMany(SelectionFactoryType = typeof(ProductInterestsFactory))] public virtual string ProductInterestType { get; set; } /// <summary> /// Gets or sets RegionType. /// </summary> /// <value> /// RegionType. /// </value> [Display( Name = "Region", Description = "Region", GroupName = SystemTabNames.PageHeader, Order = 102)] [SelectMany(SelectionFactoryType = typeof(MemberRegionsFactory))] public virtual string RegionType { get; set; } /// <summary> /// Gets or sets PreferenceType. /// </summary> /// <value> /// PreferenceType. /// </value> [Display( Name = "Preferred Destination", Description = "PreferredDestination", GroupName = SystemTabNames.PageHeader, Order = 103)] [SelectMany(SelectionFactoryType = typeof(PreferredDestinationFactory))] public virtual string PreferredDestinationType { get; set; } } } </pre>
Very simple, right?, well when the content editor (the user) creates a new block from this block type class he/she lets the default name, "New Block 1" by example, then when the content editor changes/sets the property values, I must read the property values and change, to build a string, already I have the process to do it, after, when the content editor will publish the block I must change the block name (if we remember the block was created with the "New Block 1" name) insted the new name, by example:
Content editor's selection:
ProductInterestType: 1,3
RegionType: 4
PreferredDestinationType: 5,7
And the property values corresponds to
ProductInterestType: Cruise Interest(1),(Hotel Interest)3
RegionType: (Southeast)4
PreferredDestinationType: Caribbean Exotic(7)
Then, the block name will be:
"Blog Offer for Prod: Cruise, Hotel - Rg: Southeast Dest: Caribbean"
To do it I need to catch the publish event (I think), hope to be clear
Hook to SavingContent event and set the built-in Name (from IContent) to your name. If you do it in publishing event - you may still get dialog window in UI asking you to consider renaming default block name to something more meaningful :)
You need to use an initializable module:
[InitializableModule] [ModuleDependency(typeof(EPiServer.Web.InitializationModule))] public class InitializationModule1 : IInitializableModule { public void Initialize(InitializationEngine context) { var contentEvents = context.Locate.Advanced.GetInstance<IContentEvents>(); contentEvents.SavingContent += this.SavingContent; } public void Uninitialize(InitializationEngine context) { } private void SavingContent(object sender, ContentEventArgs e) { var block = e.Content as BlogOfferBlock; if (block != null) { e.Content.Name = "Custom name" } } }
but I guess that you will still receive this annoying dialog window - as saving and publishing events are triggered on the server, but check for default name happens in client-side. haven't tested. just speculations.
The magic was done, Valdis, I did several test because I have a lot of blocks where I had to applied the change and there was no problem with any message box, I can to share the code if anybody asks me for it, thanks again to Johan and Valdis.
I'm from Mexico City, where can I know your office addresss? Valdis and Johan, I'll find the way to express my thankful
Have somebody done something about of to auto-name a Block depending from the properties selected?