private string GetFieldValue(HeaderField headerField, PublishingFunctionProcessor.FieldType fieldType = PublishingFunctionProcessor.FieldType.String) { string fieldValue = null; if (!string.IsNullOrEmpty(headerField.Functions)) { // execute function var evaluatedField = this.functionProcessor.Process(headerField.Functions, headerField.Name, fieldType); if (!string.IsNullOrEmpty(evaluatedField.Item1)) { fieldValue = evaluatedField.Item2; } } else { fieldValue = this.publishingPageTransformationInformation.SourcePage.FieldValues[headerField.Name]?.ToString().Trim(); } return(fieldValue); }
private string GetFieldValue(HeaderField headerField, PublishingFunctionProcessor.FieldType fieldType = PublishingFunctionProcessor.FieldType.String) { // check if the target field name contains a delimiter value if (headerField.Name.Contains(";")) { // extract the array of field names to process, and trims each one string[] targetFieldNames = headerField.Name.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToArray(); // sets the field name to the first "valid" entry headerField.Name = this.publishingPageTransformationInformation.GetFirstNonEmptyFieldName(targetFieldNames); } if (!string.IsNullOrEmpty(headerField.Name)) { string fieldValue = null; if (!string.IsNullOrEmpty(headerField.Functions)) { // execute function var evaluatedField = this.functionProcessor.Process(headerField.Functions, headerField.Name, fieldType); if (!string.IsNullOrEmpty(evaluatedField.Item1)) { fieldValue = evaluatedField.Item2; } } else { fieldValue = this.publishingPageTransformationInformation.SourcePage.FieldValues[headerField.Name]?.ToString().Trim(); } return(fieldValue); } else { return(null); } }
public void TransformHeader(ref ClientSidePage targetPage) { // Get the mapping model to use as it describes how the page header needs to be generated var publishingPageTransformationModel = new PageLayoutManager(this.RegisteredLogObservers).GetPageLayoutMappingModel(this.publishingPageTransformation, publishingPageTransformationInformation.SourcePage); // Configure the page header if (publishingPageTransformationModel.PageHeader == PageLayoutPageHeader.None) { targetPage.RemovePageHeader(); } else if (publishingPageTransformationModel.PageHeader == PageLayoutPageHeader.Default) { targetPage.SetDefaultPageHeader(); } else { // Custom page header // ImageServerRelativeUrl string imageServerRelativeUrl = ""; HeaderField imageServerRelativeUrlField = GetHeaderField(publishingPageTransformationModel, HeaderFieldHeaderProperty.ImageServerRelativeUrl); if (imageServerRelativeUrlField != null) { imageServerRelativeUrl = GetFieldValue(imageServerRelativeUrlField); } bool headerCreated = false; // Did we get a header image url? if (!string.IsNullOrEmpty(imageServerRelativeUrl)) { string newHeaderImageServerRelativeUrl = ""; try { // Integrate asset transformator AssetTransfer assetTransfer = new AssetTransfer(this.sourceClientContext, this.targetClientContext, base.RegisteredLogObservers); newHeaderImageServerRelativeUrl = assetTransfer.TransferAsset(imageServerRelativeUrl, System.IO.Path.GetFileNameWithoutExtension(publishingPageTransformationInformation.SourcePage[Constants.FileLeafRefField].ToString())); } catch (Exception ex) { LogError(LogStrings.Error_HeaderImageAssetTransferFailed, LogStrings.Heading_PublishingPageHeader, ex); } if (!string.IsNullOrEmpty(newHeaderImageServerRelativeUrl)) { LogInfo(string.Format(LogStrings.SettingHeaderImage, newHeaderImageServerRelativeUrl), LogStrings.Heading_PublishingPageHeader); targetPage.SetCustomPageHeader(newHeaderImageServerRelativeUrl); headerCreated = true; } } if (!headerCreated) { // let's fall back to the default header targetPage.SetDefaultPageHeader(); } // Header type handling switch (publishingPageTransformationModel.Header.Type) { case HeaderType.ColorBlock: targetPage.PageHeader.LayoutType = ClientSidePageHeaderLayoutType.ColorBlock; break; case HeaderType.CutInShape: targetPage.PageHeader.LayoutType = ClientSidePageHeaderLayoutType.CutInShape; break; case HeaderType.NoImage: targetPage.PageHeader.LayoutType = ClientSidePageHeaderLayoutType.NoImage; break; case HeaderType.FullWidthImage: targetPage.PageHeader.LayoutType = ClientSidePageHeaderLayoutType.FullWidthImage; break; } // Alignment handling switch (publishingPageTransformationModel.Header.Alignment) { case HeaderAlignment.Left: targetPage.PageHeader.TextAlignment = ClientSidePageHeaderTitleAlignment.Left; break; case HeaderAlignment.Center: targetPage.PageHeader.TextAlignment = ClientSidePageHeaderTitleAlignment.Center; break; } // Show published date targetPage.PageHeader.ShowPublishDate = publishingPageTransformationModel.Header.ShowPublishedDate; // Topic header handling HeaderField topicHeaderField = GetHeaderField(publishingPageTransformationModel, HeaderFieldHeaderProperty.TopicHeader); if (topicHeaderField != null) { if (publishingPageTransformationInformation.SourcePage.FieldExistsAndUsed(topicHeaderField.Name)) { targetPage.PageHeader.TopicHeader = publishingPageTransformationInformation.SourcePage[topicHeaderField.Name].ToString(); targetPage.PageHeader.ShowTopicHeader = true; } } // AlternativeText handling HeaderField alternativeTextHeaderField = GetHeaderField(publishingPageTransformationModel, HeaderFieldHeaderProperty.AlternativeText); if (alternativeTextHeaderField != null) { var alternativeTextHeader = GetFieldValue(alternativeTextHeaderField); if (!string.IsNullOrEmpty(alternativeTextHeader)) { targetPage.PageHeader.AlternativeText = alternativeTextHeader; } } // Authors handling if (publishingPageTransformationInformation.SourceVersion == SPVersion.SPO) { HeaderField authorsHeaderField = GetHeaderField(publishingPageTransformationModel, HeaderFieldHeaderProperty.Authors); if (authorsHeaderField != null) { var authorsHeader = GetFieldValue(authorsHeaderField, PublishingFunctionProcessor.FieldType.User); if (!string.IsNullOrEmpty(authorsHeader)) { targetPage.PageHeader.Authors = authorsHeader; } } } } }