public static Dynamic.ComponentTemplate BuildComponentTemplate(TComm.ComponentTemplate tcmComponentTemplate, BuildManager manager)
        {
            Dynamic.ComponentTemplate ct = new Dynamic.ComponentTemplate();
            ct.Title = tcmComponentTemplate.Title;
            ct.Id = tcmComponentTemplate.Id.ToString();
            ct.OutputFormat = tcmComponentTemplate.OutputFormat;
            ct.RevisionDate = tcmComponentTemplate.RevisionDate;
            if (tcmComponentTemplate.Metadata != null && tcmComponentTemplate.MetadataSchema != null)
            {
                ct.MetadataFields = new Dynamic.FieldSet();
                TCM.Fields.ItemFields tcmMetadataFields = new TCM.Fields.ItemFields(tcmComponentTemplate.Metadata, tcmComponentTemplate.MetadataSchema);
                ct.MetadataFields = manager.BuildFields(tcmMetadataFields); 
            }
            else
            {
                ct.MetadataFields = null;
            }


            if (!manager.BuildProperties.OmitContextPublications)
                ct.Publication = manager.BuildPublication(tcmComponentTemplate.ContextRepository);

            if (!manager.BuildProperties.OmitOwningPublications)
                ct.OwningPublication = manager.BuildPublication(tcmComponentTemplate.OwningRepository);

            if (!manager.BuildProperties.OmitFolders)
                ct.Folder = manager.BuildOrganizationalItem((TCM.Folder)tcmComponentTemplate.OrganizationalItem);

            return ct;
        }
        private Dynamic.ComponentPresentation GetDynamicComponentPresentation()
        {
            Template template = Engine.PublishingContext.ResolvedItem.Template;

            if (!(template is ComponentTemplate))
            {
                Log.Error("no component template found (is this a page template?)");
                return(null);
            }
            ComponentTemplate tcmComponentTemplate = (ComponentTemplate)template;
            Item item = Package.GetByName(Package.ComponentName);

            if (item == null)
            {
                Log.Error("no component found (is this a page template?)");
                return(null);
            }
            Component tcmComponent = (Component)Engine.GetObject(item);

            Dynamic.Component component = Manager.BuildComponent(tcmComponent);
            EnsureExtraProperties(component, tcmComponent);
            Dynamic.ComponentTemplate     componentTemplate     = Manager.BuildComponentTemplate(tcmComponentTemplate);
            Dynamic.ComponentPresentation componentPresentation = new Dynamic.ComponentPresentation()
            {
                Component = component, ComponentTemplate = componentTemplate, IsDynamic = tcmComponentTemplate.IsRepositoryPublishable
            };

            return(componentPresentation);
        }
		public static Dynamic.ComponentTemplate BuildComponentTemplate(TComm.ComponentTemplate tcmComponentTemplate, BuildManager manager) {
			Dynamic.ComponentTemplate ct = new Dynamic.ComponentTemplate();
			ct.Title = tcmComponentTemplate.Title;
			ct.Id = tcmComponentTemplate.Id.ToString();
			ct.OutputFormat = tcmComponentTemplate.OutputFormat;
            ct.RevisionDate = tcmComponentTemplate.RevisionDate;
         if (tcmComponentTemplate.Metadata != null && tcmComponentTemplate.MetadataSchema != null)
         {
             ct.MetadataFields = new Dynamic.FieldSet();
            TCM.Fields.ItemFields tcmMetadataFields = new TCM.Fields.ItemFields(tcmComponentTemplate.Metadata, tcmComponentTemplate.MetadataSchema);
            ct.MetadataFields = manager.BuildFields(tcmMetadataFields, 0, false,false); // never follow links to components from component templates, never resolve binary widht/height
         }
         else
         {
            ct.MetadataFields = null;
         }
         ct.Folder = manager.BuildOrganizationalItem((TCM.Folder)tcmComponentTemplate.OrganizationalItem);
         ct.Publication = manager.BuildPublication(tcmComponentTemplate.ContextRepository);
			return ct;
		}
Exemple #4
0
 public static Dynamic.ComponentTemplate BuildComponentTemplate(TComm.ComponentTemplate tcmComponentTemplate, BuildManager manager)
 {
     Dynamic.ComponentTemplate ct = new Dynamic.ComponentTemplate();
     ct.Title        = tcmComponentTemplate.Title;
     ct.Id           = tcmComponentTemplate.Id.ToString();
     ct.OutputFormat = tcmComponentTemplate.OutputFormat;
     ct.RevisionDate = tcmComponentTemplate.RevisionDate;
     if (tcmComponentTemplate.Metadata != null && tcmComponentTemplate.MetadataSchema != null)
     {
         ct.MetadataFields = new Dynamic.FieldSet();
         TCM.Fields.ItemFields tcmMetadataFields = new TCM.Fields.ItemFields(tcmComponentTemplate.Metadata, tcmComponentTemplate.MetadataSchema);
         ct.MetadataFields = manager.BuildFields(tcmMetadataFields, 0, false, false); // never follow links to components from component templates, never resolve binary widht/height
     }
     else
     {
         ct.MetadataFields = null;
     }
     ct.Folder      = manager.BuildOrganizationalItem((TCM.Folder)tcmComponentTemplate.OrganizationalItem);
     ct.Publication = manager.BuildPublication(tcmComponentTemplate.ContextRepository);
     return(ct);
 }
        public static Dynamic.ComponentTemplate BuildComponentTemplate(TComm.ComponentTemplate tcmComponentTemplate, BuildManager manager)
        {
            Dynamic.ComponentTemplate ct = new Dynamic.ComponentTemplate();
            ct.Title        = tcmComponentTemplate.Title;
            ct.Id           = tcmComponentTemplate.Id.ToString();
            ct.OutputFormat = tcmComponentTemplate.OutputFormat;
            ct.RevisionDate = tcmComponentTemplate.RevisionDate;
            if (tcmComponentTemplate.Metadata != null && tcmComponentTemplate.MetadataSchema != null)
            {
                ct.MetadataFields = new Dynamic.FieldSet();
                TCM.Fields.ItemFields tcmMetadataFields = new TCM.Fields.ItemFields(tcmComponentTemplate.Metadata, tcmComponentTemplate.MetadataSchema);
                ct.MetadataFields = manager.BuildFields(tcmMetadataFields);
            }
            else
            {
                ct.MetadataFields = null;
            }


            if (!manager.BuildProperties.OmitContextPublications)
            {
                ct.Publication = manager.BuildPublication(tcmComponentTemplate.ContextRepository);
            }

            if (!manager.BuildProperties.OmitOwningPublications)
            {
                ct.OwningPublication = manager.BuildPublication(tcmComponentTemplate.OwningRepository);
            }

            if (!manager.BuildProperties.OmitFolders)
            {
                ct.Folder = manager.BuildOrganizationalItem((TCM.Folder)tcmComponentTemplate.OrganizationalItem);
            }

            return(ct);
        }
Exemple #6
0
        private void ProcessRegions(IList <IRegion> regions, Dynamic.Page dd4tPage, int fieldCounter)
        {
            int i = fieldCounter;

            Log.Debug($"ProcessRegions {regions.Count()}, {dd4tPage.ComponentPresentations.Count()}, {fieldCounter}");
            foreach (var region in regions)
            {
                if (region.ComponentPresentations != null && region.ComponentPresentations.Any())
                {
                    foreach (var cp in region.ComponentPresentations)
                    {
                        Dynamic.Component             component             = Manager.BuildComponent(cp.Component);
                        Dynamic.ComponentTemplate     componentTemplate     = Manager.BuildComponentTemplate(cp.ComponentTemplate);
                        Dynamic.ComponentPresentation componentPresentation = new Dynamic.ComponentPresentation()
                        {
                            Component = component, ComponentTemplate = componentTemplate, IsDynamic = cp.ComponentTemplate.IsRepositoryPublishable
                        };
                        dd4tPage.ComponentPresentations.Add(componentPresentation);
                        if (componentTemplate.MetadataFields == null)
                        {
                            componentTemplate.MetadataFields = new Dynamic.FieldSet();
                        }
                        if (componentTemplate.MetadataFields.ContainsKey("region"))
                        {
                            componentTemplate.MetadataFields["region"].Values.Clear();
                            componentTemplate.MetadataFields["region"].Values.Add(region.RegionSchema.Title);
                        }
                        else
                        {
                            componentTemplate.MetadataFields.Add("region", new Dynamic.Field()
                            {
                                Name      = "region",
                                FieldType = Dynamic.FieldType.Text,
                                Values    = new List <string>()
                                {
                                    region.RegionName
                                }
                            });
                        }
                        // remove regionView metadata field, because it is no longer possible to manage this information in Tridion 9 with Regions
                        if (componentTemplate.MetadataFields.ContainsKey("regionView"))
                        {
                            componentTemplate.MetadataFields.Remove("regionView");
                        }
                        // copy all other metadata fields from the region to the entity
                        if (region.Metadata != null)
                        {
                            ItemFields regionMetadataFields = new ItemFields(region.Metadata, region.RegionSchema);
                            try
                            {
                                foreach (var regionMeta in regionMetadataFields)
                                {
                                    componentTemplate.MetadataFields.Add(regionMeta.Name, Manager.BuildField(regionMeta, 1));
                                }
                            }
                            catch (Exception e)
                            {
                                Log.Warning("error while trying to copy metadata from region to component template\r\n" + e.Message + "\r\n" + e.StackTrace);
                            }
                        }

                        if (region.Regions != null && region.RegionName.Any())
                        {
                            ProcessRegions(region.Regions, dd4tPage, i);
                        }
                    }
                }
            }
        }