Developer forum

Currently discussing: Plans to implement a Consent module for GDPR compliance.

Join the discussion!

Forum » Development » Code first items, editors with parameters.

Code first items, editors with parameters.

Simon Nordahl
Simon Nordahl
Reply

Hi Guys

I'm somewhat new to codefirst items. I'm trying to have a field with a user group selector (UserEditor), but i cant find any documentation of how to add parameters to editors when used in combination with code first items. The UserEditor is sat to default to use users and not groups, how do I change that for my codefirst item?

I cant find any ProductGroup selector for code first items, does that mean that there are none ?

 

The only documentation that i could find on the subject is http://doc.dynamicweb.com/training-certification/t3-platform-developer/t3-platform-developer/3-4-items#sideNavTitle1-2-3

 

 

Regards Simon.

Replies

 
Nicolai Pedersen
Nicolai Pedersen
Reply

Could this help?

https://doc.dynamicweb.com/api/html/d6a14638-4580-a1c9-3328-09ce262762f1.htm

BR Nicolai

 
Simon Nordahl
Simon Nordahl
Reply

Hi Nikolai

Quick answer !

But saly no, I looked at that too but still cant see how I apply the ShowType parameter to UserEditor or how to make a product group selector.

The example only makes a product selector:

        [Dynamicweb.Ecommerce.Content.Items.Annotations.Product("Product Link")]
        [Field("Product Link", typeof(Dynamicweb.Ecommerce.Content.Items.Editors.ProductEditor))]
        public string ProductLink { get; set; }

I can live without the product group selector, but the usergroup editor is vital if we are to use codefirst items.

 

 
Simon Nordahl
Simon Nordahl
Reply

I've attempted with variattions of the code below, but no matter I do it does not register parameter values.

        [Field("Users", EditorType = typeof(UserEditor)), AddInParameter("ShowTypes=1")]
        public  Dynamicweb.Security.UserManagement.Group Ggp { get; set; }

Have anybody successfully managed to make a codefirst item with a usergroup selector?

 
Simon Nordahl
Simon Nordahl
Reply

Hmm I've investigated the issue and it seems to be a bug, whenever we hit Render function in the AddInConfigurator the ConfigurableAddIn is always Nothing and thus it defaults to a default instance of the object.

 

 

       Public Property ConfigurableAddIn() As ConfigurableAddIn
            Get
                If _configurableAddIn Is Nothing Then It seems the object is always null
                    _configurableAddIn = CType(AddInManager.CreateAddInInstance(AddInType), ConfigurableAddIn) We just get the default object without any parameters.
                    _configurableAddIn.UpdateFromPost(Dynamicweb.Context.Current?.Request?.Form)
                End If
                Return _configurableAddIn
            End Get
            Set(ByVal Value As ConfigurableAddIn)
                _configurableAddIn = Value
            End Set
        End Property

 
Nicolai Pedersen
Nicolai Pedersen
Reply

Hi Simon

Thanks - will have someone look into this.
BR Nicolai

 
Vladimir Shushunov
Reply
This post has been marked as an answer

Hi Simon,

there is a way to add parameters to editor in overrided InitializeEditorConfiguration method:

 
 <AttributeUsage(AttributeTargets.Property, AllowMultiple:=False, Inherited:=False)>
    Public Class MyUserFieldAttribute
        Inherits FieldAttribute

        Public Enum ShowTypes
            Users
            Groups
            GroupsAndUsers
        End Enum

        Public Property ShowType As ShowTypes

        Public Sub New()
            Me.New(String.Empty)
        End Sub

        Public Sub New(name As String)
            MyBase.New(name, GetType(Editors.UserEditor))
        End Sub

        Protected Friend Overrides Sub InitializeEditorConfiguration(itemField As Metadata.ItemField)
            Dim userEditor As New Editors.UserEditor()
            If ShowType = ShowTypes.GroupsAndUsers Then
                userEditor.ShowTypes = "1,2"
            ElseIf ShowType = ShowTypes.Groups Then
                userEditor.ShowTypes = "1"
            Else
                userEditor.ShowTypes = "2"
            End If

            itemField.EditorConfiguration = userEditor.GetParametersToXml(False)
        End Sub

    End Class

And then it could be used:

        [MyUserField(Name ="User")]
        public string FieldUser { get; set; }

        [MyUserField(Name = "Group", ShowType = UserAttribute.ShowTypes.Groups)]
        public string FieldGroup { get; set; }

        [MyUserField(Name = "Group and users", ShowType = UserAttribute.ShowTypes.GroupsAndUsers)]
        public string FieldGroupsAndUsers { get; set; }

Probably it has sense to add this code as part of default functionality in the next releases

Best regards, 
Vladimir

Votes for this answer: 1
 
Simon Nordahl
Simon Nordahl
Reply

Hi Vladimir

Thanks for the reply, I definitely think it’s a great idea to have a way of setting the parameter values. I was sure that it was an error on my part, as I was convinced there would be a way to send the parameter.

Perhaps we could have a general attribute, so it would be possible to set parameters on all the field types?

I have made a temporary workaround by making a new editor inherited from UserEditor like so:

    public class CodeFirstItem : ItemEntry
    {
        [Field("User groups", EditorType = typeof(UserGroupEditor))]
        public IEnumerable<string> UserGroups { get; set; }
    }

    public sealed class UserGroupEditor : UserEditor
    {
        public UserGroupEditor()
        {
            ShowTypes = "1";
        }
    }

Next up, for me, is a ProductGroup editor :)

 

Kind regards 

Simon

 

 
Vladimir Shushunov
Reply

Hi Simon,

sorry for delay, we discussed a lot the group selecting feature :)

We will try to add it to the next release / hotfix. The ProductEditor wil acquire 2 checkboxes: Groups and Products

btw could you say how you going to use these values? Do you need rendering of products inside selected groups (when an item is rendered on frontend)?

Best regards,
Vladimir

 

 

You must be logged in to post in the forum