#pragma warning restore 0109

        // ctor
        public InfoItem(IPublishedElement content)
            : base(content)
        {
        }
 public DocumentComponent(IPublishedElement content) : base(content)
 {
 }
#pragma warning restore 0109

        // ctor
        public PortfolioAreaFilter(IPublishedElement content)
            : base(content)
        {
        }
#pragma warning restore 0109

        // ctor
        public ColumnSettingsComposition(IPublishedElement content)
            : base(content)
        {
        }
Beispiel #5
0
        /// <inheritdoc />
        public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
        {
            // NOTE: The intermediate object is just a json string, we don't actually convert from source -> intermediate since source is always just a json string

            using (_proflog.DebugDuration <BlockListPropertyValueConverter>($"ConvertPropertyToBlockList ({propertyType.DataType.Id})"))
            {
                var configuration            = propertyType.DataType.ConfigurationAs <BlockListConfiguration>();
                var blockConfigMap           = configuration.Blocks.ToDictionary(x => x.ContentElementTypeKey);
                var validSettingElementTypes = blockConfigMap.Values.Select(x => x.SettingsElementTypeKey).Where(x => x.HasValue).Distinct().ToList();

                var contentPublishedElements  = new Dictionary <Guid, IPublishedElement>();
                var settingsPublishedElements = new Dictionary <Guid, IPublishedElement>();

                var layout = new List <BlockListItem>();

                var value = (string)inter;
                if (string.IsNullOrWhiteSpace(value))
                {
                    return(BlockListModel.Empty);
                }

                var converted = _blockListEditorDataConverter.Deserialize(value);
                if (converted.BlockValue.ContentData.Count == 0)
                {
                    return(BlockListModel.Empty);
                }

                var blockListLayout = converted.Layout.ToObject <IEnumerable <BlockListLayoutItem> >();

                // convert the content data
                foreach (var data in converted.BlockValue.ContentData)
                {
                    if (!blockConfigMap.ContainsKey(data.ContentTypeKey))
                    {
                        continue;
                    }

                    var element = _blockConverter.ConvertToElement(data, referenceCacheLevel, preview);
                    if (element == null)
                    {
                        continue;
                    }
                    contentPublishedElements[element.Key] = element;
                }
                // convert the settings data
                foreach (var data in converted.BlockValue.SettingsData)
                {
                    if (!validSettingElementTypes.Contains(data.ContentTypeKey))
                    {
                        continue;
                    }

                    var element = _blockConverter.ConvertToElement(data, referenceCacheLevel, preview);
                    if (element == null)
                    {
                        continue;
                    }
                    settingsPublishedElements[element.Key] = element;
                }

                // if there's no elements just return since if there's no data it doesn't matter what is stored in layout
                if (contentPublishedElements.Count == 0)
                {
                    return(BlockListModel.Empty);
                }

                foreach (var layoutItem in blockListLayout)
                {
                    // get the content reference
                    var contentGuidUdi = (GuidUdi)layoutItem.ContentUdi;
                    if (!contentPublishedElements.TryGetValue(contentGuidUdi.Guid, out var contentData))
                    {
                        continue;
                    }

                    // get the setting reference
                    IPublishedElement settingsData = null;
                    var settingGuidUdi             = layoutItem.SettingsUdi != null ? (GuidUdi)layoutItem.SettingsUdi : null;
                    if (settingGuidUdi != null)
                    {
                        settingsPublishedElements.TryGetValue(settingGuidUdi.Guid, out settingsData);
                    }

                    if (!contentData.ContentType.TryGetKey(out var contentTypeKey))
                    {
                        throw new InvalidOperationException("The content type was not of type " + typeof(IPublishedContentType2));
                    }

                    if (!blockConfigMap.TryGetValue(contentTypeKey, out var blockConfig))
                    {
                        continue;
                    }

                    // this can happen if they have a settings type, save content, remove the settings type, and display the front-end page before saving the content again
                    // we also ensure that the content type's match since maybe the settings type has been changed after this has been persisted.
                    if (settingsData != null)
                    {
                        if (!settingsData.ContentType.TryGetKey(out var settingsElementTypeKey))
                        {
                            throw new InvalidOperationException("The settings element type was not of type " + typeof(IPublishedContentType2));
                        }

                        if (!blockConfig.SettingsElementTypeKey.HasValue || settingsElementTypeKey != blockConfig.SettingsElementTypeKey)
                        {
                            settingsData = null;
                        }
                    }

                    // TODO: This should be optimized/cached, as calling Activator.CreateInstance is slow
                    var layoutType = typeof(BlockListItem <,>).MakeGenericType(contentData.GetType(), settingsData?.GetType() ?? typeof(IPublishedElement));
                    var layoutRef  = (BlockListItem)Activator.CreateInstance(layoutType, contentGuidUdi, contentData, settingGuidUdi, settingsData);

                    layout.Add(layoutRef);
                }

                var model = new BlockListModel(layout);
                return(model);
            }
        }
#pragma warning restore 0109

        // ctor
        public BlueBlock(IPublishedElement content)
            : base(content)
        {
        }
Beispiel #7
0
        // default ConvertSourceToObject just returns source ie a boolean value

        public override object ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object?inter, bool preview)
        {
            // source should come from ConvertSource and be a boolean already
            return((bool?)inter ?? false ? "1" : "0");
        }
#pragma warning restore 0109

        // ctor
        public SiteNavNavSection(IPublishedElement content)
            : base(content)
        {
        }
 public static MvcHtmlString GetGridHtml(this HtmlHelper html, IPublishedElement contentItem)
 {
     return(html.GetGridHtml(contentItem, "bodyText", "bootstrap3"));
 }
    public override object ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object?inter, bool preview) =>

    // source should come from ConvertSource and be a string (or null) already
    inter?.ToString() ?? string.Empty;
 /// <inheritdoc />
 public bool TryGetValue <T>(IPublishedElement content, string alias, string culture, string segment, Fallback fallback, T defaultValue, out T value)
 {
     value = default;
     return(false);
 }
Beispiel #12
0
 /// <inheritdoc />
 public virtual void WriteProperty(TextWriter writer, IPublishedElement owner, IPublishedProperty property, string culture = null, string segment = null)
 {
     WriteValue(writer, property.Value(culture, segment));
 }
Beispiel #13
0
        public ContentModel ResolveContent(IPublishedElement content)
        {
            try
            {
                if (content == null)
                {
                    throw new ArgumentNullException(nameof(content));
                }

                var contentModel = new ContentModel
                {
                    System = new SystemModel
                    {
                        Id          = content.Key,
                        ContentType = content.ContentType.Alias,
                        Type        = content.ContentType.ItemType.ToString()
                    }
                };

                var dict = new Dictionary <string, object>();

                if (content is IPublishedContent publishedContent)
                {
                    contentModel.System.CreatedAt  = publishedContent.CreateDate;
                    contentModel.System.EditedAt   = publishedContent.UpdateDate;
                    contentModel.System.Locale     = _variationContextAccessor.VariationContext.Culture;
                    contentModel.System.Revision   = _contentService.GetVersions(publishedContent.Id).Count();
                    contentModel.System.Name       = publishedContent.Name;
                    contentModel.System.UrlSegment = publishedContent.UrlSegment;
                }

                foreach (IPublishedProperty property in content.Properties)
                {
                    IConverter converter =
                        _converters.FirstOrDefault(x => x.EditorAlias.Equals(property.PropertyType.EditorAlias));
                    if (converter != null)
                    {
                        object prop = property.Value();

                        if (prop == null)
                        {
                            continue;
                        }

                        prop = converter.Convert(prop);
                        dict.Add(property.Alias, prop);
                    }
                    else
                    {
                        dict.Add(
                            property.Alias,
                            $"No converter implemented for editor: {property.PropertyType.EditorAlias}");
                    }
                }

                contentModel.Fields = dict;
                return(contentModel);
            }
            catch (Exception e)
            {
                _logger.Error <ContentResolver>(e);
                throw;
            }
        }
Beispiel #14
0
#pragma warning restore 0109

        // ctor
        public Period(IPublishedElement content)
            : base(content)
        {
        }
Beispiel #15
0
        public static T As <T>(this IPublishedElement content)
        {
            var type = typeof(T);

            return((T)As(content, type));
        }
#pragma warning restore 0109

        // ctor
        public Testimonial(IPublishedElement content)
            : base(content)
        {
        }
 /// <inheritdoc />
 /// <summary>
 /// Initializes a new instance of the <see cref="PublishedElementModel"/> class with
 /// an original <see cref="IPublishedElement"/> instance.
 /// </summary>
 /// <param name="content">The original content.</param>
 protected PublishedElementModel(IPublishedElement content)
     : base(content)
 {
 }
Beispiel #18
0
 /// <inheritdoc />
 public bool TryGetValue(IPublishedElement content, string alias, string?culture, string?segment, Fallback fallback, object?defaultValue, out object?value) =>
 TryGetValue <object>(content, alias, culture, segment, fallback, defaultValue, out value);
Beispiel #19
0
#pragma warning restore 0109

        // ctor
        public NavigationNC(IPublishedElement content)
            : base(content)
        {
        }
#pragma warning restore 0109

        // ctor
        public FontAwesomeComposition(IPublishedElement content)
            : base(content)
        {
        }
Beispiel #21
0
 public PredefinedAmount(IPublishedElement content)
 {
     Currency = content.Value <string>("currency");
     Amounts  = content.Value <string[]>("amounts");
 }
Beispiel #22
0
 /// <inheritdoc />
 public bool TryGetValue(IPublishedElement content, string alias, string culture, string segment, Fallback fallback, object defaultValue, out object value)
 {
     return(TryGetValue <object>(content, alias, culture, segment, fallback, defaultValue, out value));
 }
Beispiel #23
0
 /// <inheritdoc />
 public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
 {
     return(source?.ToString());
 }
#pragma warning restore 0109

        // ctor
        public Feature(IPublishedElement content)
            : base(content)
        {
        }
#pragma warning restore 0109

        // ctor
        public SlideSubtitleControls(IPublishedElement content)
            : base(content)
        {
        }
Beispiel #26
0
        public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel cacheLevel, object source, bool preview)
        {
            if (source == null)
            {
                return(null);
            }

            // TODO: Inject an UmbracoHelper and create a GetUmbracoHelper method based on either injected or singleton
            if (_umbracoContextAccessor.TryGetUmbracoContext(out _))
            {
                if (propertyType.EditorAlias.Equals(Constants.PropertyEditors.Aliases.MultiNodeTreePicker))
                {
                    var udis = (Udi[])source;
                    var isSingleNodePicker = IsSingleNodePicker(propertyType);

                    if ((propertyType.Alias != null && PropertiesToExclude.InvariantContains(propertyType.Alias)) == false)
                    {
                        var multiNodeTreePicker = new List <IPublishedContent>();

                        var objectType        = UmbracoObjectTypes.Unknown;
                        var publishedSnapshot = _publishedSnapshotAccessor.GetRequiredPublishedSnapshot();
                        foreach (var udi in udis)
                        {
                            var guidUdi = udi as GuidUdi;
                            if (guidUdi == null)
                            {
                                continue;
                            }

                            IPublishedContent multiNodeTreePickerItem = null;
                            switch (udi.EntityType)
                            {
                            case Constants.UdiEntityType.Document:
                                multiNodeTreePickerItem = GetPublishedContent(udi, ref objectType, UmbracoObjectTypes.Document, id => publishedSnapshot.Content.GetById(guidUdi.Guid));
                                break;

                            case Constants.UdiEntityType.Media:
                                multiNodeTreePickerItem = GetPublishedContent(udi, ref objectType, UmbracoObjectTypes.Media, id => publishedSnapshot.Media.GetById(guidUdi.Guid));
                                break;

                            case Constants.UdiEntityType.Member:
                                multiNodeTreePickerItem = GetPublishedContent(udi, ref objectType, UmbracoObjectTypes.Member, id =>
                                {
                                    IMember m = _memberService.GetByKey(guidUdi.Guid);
                                    if (m == null)
                                    {
                                        return(null);
                                    }
                                    IPublishedContent member = publishedSnapshot.Members.Get(m);
                                    return(member);
                                });
                                break;
                            }

                            if (multiNodeTreePickerItem != null && multiNodeTreePickerItem.ContentType.ItemType != PublishedItemType.Element)
                            {
                                multiNodeTreePicker.Add(multiNodeTreePickerItem);
                                if (isSingleNodePicker)
                                {
                                    break;
                                }
                            }
                        }

                        if (isSingleNodePicker)
                        {
                            return(multiNodeTreePicker.FirstOrDefault());
                        }
                        return(multiNodeTreePicker);
                    }

                    // return the first nodeId as this is one of the excluded properties that expects a single id
                    return(udis.FirstOrDefault());
                }
            }
            return(source);
        }
#pragma warning restore 0109

        // ctor
        public MiniIcon(IPublishedElement content)
            : base(content)
        {
        }
 /// <summary>
 /// Gets a value indicating whether the content is visible.
 /// </summary>
 /// <param name="content">The content.</param>
 /// <returns>A value indicating whether the content is visible.</returns>
 /// <remarks>A content is not visible if it has an umbracoNaviHide property with a value of "1". Otherwise,
 /// the content is visible.</remarks>
 public static bool IsVisible(this IPublishedElement content) => content.IsVisible(PublishedValueFallback);
Beispiel #29
0
#pragma warning restore 0109

        // ctor
        public CardBlock(IPublishedElement content)
            : base(content)
        {
        }
#pragma warning restore 0109

        // ctor
        public SectionHeader(IPublishedElement content)
            : base(content)
        {
        }