AllowedTypes doesn't work for OptimizingBlock

Vote:
 

Hi All,
In our project we use AllowedTypes attribute with content areas.
It works well for Blocks defined in our code.
Recently client asked us to install well-known "Self-Optimizing Block" Add-On and allow this block to be added to content areas which have AllowedTypes restrictions.
We referenced EPiServer.Cms.AddOns.Blocks.dll lib and configured "AllowedTypes":

[AllowedTypes(typeof(TestBlock), typeof(OptimizingBlock))]
public virtual ContentArea TestContentArea { get; set; }

The problem is that drag&drop doesn't work for OptimizingBlocks in All-Properties edit mode. But Drag&Drop works fine for other allowed blocks.

Why it doesn't work for OptimizingBlock?

#86856
Jun 03, 2014 14:23
Vote:
 

I have checked [uipath]/shell/Stores/uidescriptor and found out that dndTypes are strange for optimizingblock.

For other types which has no problems with dran&drop "dndTypes" are equal to "typeIdentifier"...

[
{
"typeIdentifier":"episerver.cms.addons.blocks.optimizingblock",
"baseTypeIdentifier":"episerver.core.blockdata",
"iconClass":"epi-iconObjectOptimizingBlock",
"dndTypes":["epi.cms.block.lighturi","epi.cms.content.lighturi"],
"languageKey":"optimizingblock",
},

Can anybody help me understand the problem?

Why Optimizingblock has such strange dndTypes?

How to change dndTypes?

#86938
Edited, Jun 04, 2014 17:39
Vote:
 

Hey, any follow up on this issue?

#112310
Oct 27, 2014 16:16
Vote:
 

Hi,

This is now fixed with the latest release of self optimizing block. You can update it from the add-ons menu.

#112878
Nov 06, 2014 16:40
Vote:
 

Thanks for update Josef, works nice now!

#112899
Nov 07, 2014 9:55
Vote:
 

Hi!

Here is some code for a custom attribute that extends the normal AllowedTypes attribute to accept optimizing blocks. Note that this does not actually prevent adding an optimizing block with content that is now allowed according to the allowed types attribute:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using EPiServer.Shell.ObjectEditing;

namespace Samples
{
    /// <summary>
    /// Assigns types that the property accepts adding.
    /// </summary>
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
    public sealed class CustomAllowedTypesAttribute : Attribute, IMetadataAware
    {
        private Type[] _allowedTypes;

        /// <summary>
        /// Initializes a new instance of the <see cref="AllowedTypesAttribute"/> class.
        /// </summary>
        public CustomAllowedTypesAttribute()
            : this(new Type[0])
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="AllowedTypesAttribute" /> class.
        /// </summary>
        /// <param name="allowedTypes">The allowed types.</param>
        public CustomAllowedTypesAttribute(params Type[] allowedTypes)
        {
            _allowedTypes = allowedTypes;
        }

        /// <summary>
        /// Gets the allowed types.
        /// </summary>
        /// <value>
        /// The allowed types.
        /// </value>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "Attributes can not contain properties that contain collections")]
        public Type[] AllowedTypes
        {
            get
            {
                return (Type[])_allowedTypes.Clone();
            }
        }

        /// <summary>
        /// Gets or sets the allowed types format suffix.
        /// </summary>
        /// <value>
        /// The allowed types format suffix.
        /// </value>
        public string AllowedTypesFormatSuffix { get; set; }

        /// <summary>
        /// Adds the allowed types to the metadata.
        /// </summary>
        /// <param name="metadata">The model metadata.</param>
        public void OnMetadataCreated(ModelMetadata metadata)
        {
            var extendedMetadata = metadata as ExtendedMetadata;

            if (extendedMetadata != null)
            {
                List<string> allowedTypesWithFormat = _allowedTypes.Select(a => a.FullName.ToLowerInvariant()).ToList();

                AddOptimizingBlock(allowedTypesWithFormat);

                extendedMetadata.EditorConfiguration["AllowedTypes"] = allowedTypesWithFormat.ToArray();

                if (!String.IsNullOrEmpty(AllowedTypesFormatSuffix))
                {
                    allowedTypesWithFormat = allowedTypesWithFormat.Select(a => a + "." + AllowedTypesFormatSuffix).ToList();
                }

                extendedMetadata.EditorConfiguration["AllowedDndTypes"] = allowedTypesWithFormat;
                extendedMetadata.OverlayConfiguration["AllowedDndTypes"] = allowedTypesWithFormat;
            }
        }

        private static void AddOptimizingBlock(List<string> allowedTypesWithFormat)
        {
            allowedTypesWithFormat.Add("episerver.cms.addons.blocks.optimizingblock");
        }
    }
}
#112906
Nov 07, 2014 11:01
Vote:
 

This site can’t be reached

The webpage at https://koala.mazda.com.au/koala-cms/CMS/Content/contentassets/d5c62d86536745ed93c6529019bba7fb,,91291might be temporarily down or it may have moved permanently to a new web address.

ERR_CONTENT_DECODING_FAILED
Hi there!
I had created an Optimized block (ID =91291) in page , once when I want Edit that I've got the above error but for through All Property button it works fine and I am able to edit that
any idea about the why I've got this error? 
#180329
Jul 06, 2017 9:26