public virtual T Load(IBlockEntity entity, StoryViewMode viewMode) { Guard.NotNull(entity, nameof(entity)); var block = Create(entity); var json = entity.Model; if (json.IsEmpty()) { return(block); } JsonConvert.PopulateObject(json, block); if (block is IBindableBlock bindableBlock) { bindableBlock.BindEntityName = entity.BindEntityName; bindableBlock.BindEntityId = entity.BindEntityId; } return(block); }
public override SampleBlock Load(IBlockEntity entity, StoryViewMode viewMode) { var block = base.Load(entity, viewMode); // By default 'BlockHandlerBase<TBlock>' stores block instance data as JSON in the 'Model' field of the 'PageStoryBlock' table. // You can, however, store data anywhere you like and override loading behaviour in this method. if (viewMode == StoryViewMode.Edit) { // You can prepare your model especially for the edit mode of the block, // e.g. add some SelectListItems for dropdownmenus which you will only need in the edit mode of the block block.MyProperties.Add(new SelectListItem { Text = "Item1", Value = "1" }); } else if (viewMode == StoryViewMode.GridEdit) { // Manipulate properties especially for the grid edit mode e.g. turn of any animation which could distract the user from editing the grid. //block.Autoplay = false; } return(block); }
public virtual void BeforeRender(IBlockContainer container, StoryViewMode viewMode, IBlockHtmlParts htmlParts) { // Default impl does nothing. }