Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dave Hanvey 15 posts 96 karma points
    Jul 03, 2019 @ 10:00
    Dave Hanvey
    1

    Macro Parameters missing Multiple Media Picker

    I used the Gallery snippet when creating a Macro. In it says to use Multiple Media Picker as the Editor however this option is not listed - just the single Media Picker.

    Is there a workaround? as it's the multiple selection of images I want to enable for the user.

    Thanks for any help anyone can be.

  • Pasang Tamang 258 posts 458 karma points
    Jul 15, 2019 @ 17:44
    Pasang Tamang
    0

    Hi Dave,

    I had exactly same problem. I did check in Umbraco core code to see how it is working in other sides. Then I found with some tweak it can be done. I release my findings as a package. Please check this and see if it helps you?

    Thanks

    Regards, Pasang

  • Dave Hanvey 15 posts 96 karma points
    Jul 16, 2019 @ 07:05
    Dave Hanvey
    0

    Thanks for your reply. When I click on the link I get a 'package not found' message. In the end, for the site I was building, I just reworked the setup and didn't use the macro approach. Thanks again for your reply.

  • rj 8 posts 99 karma points
    Jul 22, 2019 @ 00:38
    rj
    0

    Simply add the following anywhere in your project

    using Umbraco.Core;
    using Umbraco.Core.Logging;
    using Umbraco.Core.PropertyEditors;
    
    namespace Umbraco.Web.PropertyEditors
    {
        [DataEditor("Umbraco.MultipleMediaPicker", EditorType.MacroParameter,
            "Multiple Media Picker", "mediapicker", ValueType = ValueTypes.Text, Group = "media", Icon = Constants.Icons.MediaImage)]
        public class MultipleMediaPickerPropertyEditor : DataEditor
        {
            public MultipleMediaPickerPropertyEditor(ILogger logger)
                : base(logger)
            { }
    
            protected override IConfigurationEditor CreateConfigurationEditor() => new MultipleMediaPickerConfigurationEditor();
        }
    
        public class MultipleMediaPickerConfigurationEditor : MediaPickerConfigurationEditor
        {
            public override object DefaultConfigurationObject => new MediaPickerConfiguration()
            {
                Multiple = true
            };
        }
    }
    

    You can change other default config values by changing more of the MediaPickerConfiguration properties in the MultipleMediaPickerConfigurationEditor class

    All of the properties available can be seen here:

    https://github.com/umbraco/Umbraco-CMS/blob/v8/dev/src/Umbraco.Web/PropertyEditors/MediaPickerConfiguration.cs


    The benefit of defining the property editor programatically (as opposed to a package.manifest) in this instance is that we're able to specify it to only be a macro parameter by only setting its type to EditorType.MacroParameter.

    That means it will not show up in the list of available property editors when adding or editing a data type and only show up when adding a macro parameter.

  • Dave Hanvey 15 posts 96 karma points
    Jul 22, 2019 @ 09:18
    Dave Hanvey
    0

    Many thanks!

  • rj 8 posts 99 karma points
    Jul 22, 2019 @ 19:38
    rj
    0

    Just a heads up, I changed the alias for the property editor to "Umbraco.MultipleMediaPicker" which is the same as it was in v7 (ref).

    That way if Umbraco is updated to officially re-add it with its original alias you wont have to change your macros again (you would have to remove the hotfix code though, otherwise you'll get a YSOD complaining about two property editors having the same alias).

Please Sign in or register to post replies

Write your reply to:

Draft