ContentProvider examples for #EPiServer Part two

Sometimes you want to customize your mirrored content, in this example I can customize the url segment, setting the ACLs, and localization. And we do use Fetchdata.

This blog post covers an other way to build up the mirrored page.

This is a continuation of the previous blog post:

Contentprovider example for #EPiServer, Former PageProvider, Part one

Sometimes you want to customize your mirrored content, in this example I can customize the url segment, setting the ACLs, and localization. We do use Fetchdata from instead of setting all properties or using CreateWritableClone(), when FetchData is used it is important to set the property PageShortcutLink to the original ContentLink.

public IContent CreateMirroredContent(MappedIdentity mappedIdentity, PageData original)
{
            ContentType type = _contentTypeRepository.Load(typeof(EpiPageTypes.Common.ContactCard));


            var mirrored = _contentFactory.CreateContent(type);
            
            //nope using FetchData from instead
            //EpiPageTypes.Common.ContactCard mirrored = original.CreateWritableClone() as EpiPageTypes.Common.ContactCard;

           
            mirrored.ParentLink = new PageReference(EntryPoint.ID);
            mirrored.ContentTypeID = type.ID;


            mirrored.ContentLink = mappedIdentity.ContentLink;
            mirrored.ContentGuid = mappedIdentity.ContentGuid;
           
            ((EpiPageTypes.Common.ContactCard)mirrored).LinkType = PageShortcutType.FetchData;
            mirrored.Property["PageShortcutLink"].Value = original.ContentLink;

            mirrored.Name = original.Name;
            //Cutomize the url segment if you want
            (mirrored as IRoutable).RouteSegment = _urlSegment.Create(mirrored.Name).Replace(" ", "-").Replace(".", "");
            ((EpiPageTypes.Common.ContactCard)mirrored).LinkURL = base.ConstructContentUri(type.ID, mirrored.ContentLink, mirrored.ContentGuid).ToString();
            
           

            var securable = mirrored as IContentSecurable;
            securable.GetContentSecurityDescriptor().AddEntry(new AccessControlEntry(EveryoneRole.RoleName, AccessLevel.Read));

            ILocalizable localizable = mirrored as ILocalizable; 
            var langs = new List();
            langs.Add(new CultureInfo("en"));
            langs.Add(new CultureInfo("sv"));
            localizable.ExistingLanguages = langs;
            localizable.Language = original.Language;

            var versionable = mirrored as IVersionable;
            if (versionable != null)
            {
                versionable.Status = VersionStatus.Published;
            }

            var changeTrackable = mirrored as IChangeTrackable;
            if (changeTrackable != null)
            {
                changeTrackable.Changed = original.Changed;
            }


            ((EpiPageTypes.Common.ContactCard)mirrored).MakeReadOnly();

            return mirrored;
}

Leave a Reply

Your email address will not be published. Required fields are marked *