public static void ConvertItemValueFromV011(JObject item, int dtdId, ref PreValueCollection preValues)
        {
            var contentTypeAlias = GetContentTypeAliasFromItem(item);

            if (contentTypeAlias != null)
            {
                // the item is already in >v0.1.1 format
                return;
            }

            // old style (v0.1.1) data, let's attempt a conversion
            // - get the prevalues (if they're not loaded already)
            preValues = preValues ?? GetPreValuesCollectionByDataTypeId(dtdId);

            // - convert the prevalues (if necessary)
            ConvertPreValueCollectionFromV011(preValues);

            // - get the content types prevalue as JArray
            var preValuesAsDictionary = preValues.AsPreValueDictionary();

            if (!preValuesAsDictionary.ContainsKey(ContentTypesPreValueKey) || string.IsNullOrEmpty(preValuesAsDictionary[ContentTypesPreValueKey]) != false)
            {
                return;
            }

            var preValueContentTypes = JArray.Parse(preValuesAsDictionary[ContentTypesPreValueKey]);

            if (preValueContentTypes.Any())
            {
                // the only thing we can really do is assume that the item is the first available content type
                item[NestedContentPropertyEditor.ContentTypeAliasPropertyKey] = preValueContentTypes.First().Value <string>("ncAlias");
            }
        }
示例#2
0
            public override void ConfigureForDisplay(PreValueCollection preValues)
            {
                base.ConfigureForDisplay(preValues);

                var asDictionary = preValues.AsPreValueDictionary();

                if (asDictionary.ContainsKey("hideLabel"))
                {
                    var boolAttempt = asDictionary["hideLabel"].TryConvertTo <bool>();
                    if (boolAttempt.Success)
                    {
                        HideLabel = boolAttempt.Result;
                    }
                }
            }
        public static void ConvertPreValueCollectionFromV011(PreValueCollection preValueCollection)
        {
            if (preValueCollection == null)
            {
                return;
            }

            var persistedPreValuesAsDictionary = preValueCollection.AsPreValueDictionary();

            // do we have a "docTypeGuid" prevalue and no "contentTypes" prevalue?
            if (persistedPreValuesAsDictionary.ContainsKey("docTypeGuid") == false || persistedPreValuesAsDictionary.ContainsKey(ContentTypesPreValueKey))
            {
                // the prevalues are already in >v0.1.1 format
                return;
            }

            // attempt to parse the doc type guid
            Guid guid;

            if (Guid.TryParse(persistedPreValuesAsDictionary["docTypeGuid"], out guid) == false)
            {
                // this shouldn't happen... but just in case.
                return;
            }

            // find the content type
            var contentType = ApplicationContext.Current.Services.ContentTypeService.GetAllContentTypes().FirstOrDefault(c => c.Key == guid);

            if (contentType == null)
            {
                return;
            }

            // add a prevalue in the format expected by the new (>0.1.1) content type picker/configurator
            preValueCollection.PreValuesAsDictionary[ContentTypesPreValueKey] = new PreValue(
                string.Format(@"[{{""ncAlias"": ""{0}"", ""ncTabAlias"": ""{1}"", ""nameTemplate"": ""{2}"", }}]",
                              contentType.Alias,
                              persistedPreValuesAsDictionary["tabAlias"],
                              persistedPreValuesAsDictionary["nameTemplate"]
                              )
                );
        }
示例#4
0
        public static IContentType GetContentTypeFromPreValue(PreValueCollection preValues)
        {
            var preValuesDict = preValues.AsPreValueDictionary();

            Guid contentTypeGuid;

            if (!preValuesDict.ContainsKey("docTypeGuid") || !Guid.TryParse(preValuesDict["docTypeGuid"], out contentTypeGuid))
            {
                return(null);
            }

            var contentTypeAlias = ApplicationContext.Current.Services.ContentTypeService.GetAliasByGuid(Guid.Parse(preValuesDict["docTypeGuid"]));
            var contentType      = ApplicationContext.Current.Services.ContentTypeService.GetContentType(contentTypeAlias);

            if (contentType == null || contentType.PropertyTypes == null)
            {
                return(null);
            }

            return(contentType);
        }