/// <summary> /// Loads the web part form. /// </summary> protected void LoadForm() { // Load settings if (!string.IsNullOrEmpty(Request.Form[hdnIsNewWebPart.UniqueID])) { IsNewWebPart = ValidationHelper.GetBoolean(Request.Form[hdnIsNewWebPart.UniqueID], false); } if (!string.IsNullOrEmpty(Request.Form[hdnInstanceGUID.UniqueID])) { InstanceGUID = ValidationHelper.GetGuid(Request.Form[hdnInstanceGUID.UniqueID], Guid.Empty); } // Indicates whether the new variant should be chosen when closing this dialog selectNewVariant = IsNewVariant; // Try to find the web part variant in the database and set its VariantID if (IsNewVariant) { Hashtable varProperties = WindowHelper.GetItem("variantProperties") as Hashtable; if (varProperties != null) { // Get the variant code name from the WindowHelper string variantName = ValidationHelper.GetString(varProperties["codename"], string.Empty); // Check if the variant exists in the database int variantIdFromDB = VariantHelper.GetVariantID(VariantMode, PageTemplateID, variantName, true); // Set the variant id from the database if (variantIdFromDB > 0) { VariantID = variantIdFromDB; IsNewVariant = false; } } } if (!String.IsNullOrEmpty(WebPartID)) { // Get the page info pi = CMSWebPartPropertiesPage.GetPageInfo(AliasPath, PageTemplateID, CultureCode); if (pi == null) { ShowError(GetString("general.pagenotfound")); pnlExport.Visible = false; return; } // Get template pti = pi.UsedPageTemplateInfo; // Get template instance templateInstance = pti.TemplateInstance; if (!IsNewWebPart) { // Standard zone webPartInstance = templateInstance.GetWebPart(InstanceGUID, WebPartID); // If the web part not found, try to find it among the MVT/CP variants if (webPartInstance == null) { // MVT/CP variant // Clone templateInstance to avoid caching of the temporary template instance loaded with CP/MVT variants var tempTemplateInstance = templateInstance.Clone(); tempTemplateInstance.LoadVariants(false, VariantModeEnum.None); webPartInstance = tempTemplateInstance.GetWebPart(InstanceGUID, -1); // Set the VariantMode according to the selected web part/zone variant if (webPartInstance?.ParentZone != null) { VariantMode = (webPartInstance.VariantMode != VariantModeEnum.None) ? webPartInstance.VariantMode : webPartInstance.ParentZone.VariantMode; } else { VariantMode = VariantModeEnum.None; } } else { // Ensure that the ZoneVariantID is not set when the web part was found in a regular zone ZoneVariantID = 0; } if ((VariantID > 0) && webPartInstance?.PartInstanceVariants != null) { // Check OnlineMarketing permissions. if (CheckPermissions("Read")) { webPartInstance = webPartInstance.FindVariant(VariantID); } else { // Not authorized for OnlineMarketing - Manage. RedirectToInformation(String.Format(GetString("general.permissionresource"), "Read", (VariantMode == VariantModeEnum.ContentPersonalization) ? "CMS.ContentPersonalization" : "CMS.MVTest")); } } if (webPartInstance == null) { UIContext.EditedObject = null; return; } } // Keep xml version if (webPartInstance != null) { xmlVersion = webPartInstance.XMLVersion; } // Get the form info FormInfo fi = GetWebPartFormInfo(); // Get the form definition if (fi != null) { fi.ContextResolver.Settings.RelatedObject = templateInstance; form.AllowMacroEditing = true; // Get data row with required columns DataRow dr = fi.GetDataRow(); if (IsNewWebPart || (xmlVersion > 0)) { fi.LoadDefaultValues(dr); } // Load values from existing web part LoadDataRowFromWebPart(dr, webPartInstance, fi); // Set a unique WebPartControlID for the new variant if (IsNewVariant || IsNewWebPart) { dr["WebPartControlID"] = GetUniqueWebPartId(); } // Init the form InitForm(form, dr, fi); DisplayExportPropertiesButton(); } else { UIContext.EditedObject = null; } } }