Exemple #1
0
        public NameValueCollection ReadElementValues(Form form, IValueProvider valueProvider)
        {
            var formElements = GetFormElements(form);
            var values       = new NameValueCollection();

            // Let each element provide its values.
            foreach (var element in formElements)
            {
                var context = new ReadElementValuesContext {
                    ValueProvider = valueProvider
                };
                ReadElementValues(element, context);

                foreach (var key in from string key in context.Output where !String.IsNullOrWhiteSpace(key) && values[key] == null select key)
                {
                    values.Add(key, context.Output[key]);
                }
            }

            // Collect any remaining form values not handled by any specific element.
            var requestForm = _services.WorkContext.HttpContext.Request.Form;
            var blackList   = new[] { "__RequestVerificationToken", "formName", "contentId" };

            foreach (var key in
                     from string key in requestForm
                     where !String.IsNullOrWhiteSpace(key) && !blackList.Contains(key) && values[key] == null
                     select key)
            {
                values.Add(key, requestForm[key]);
            }

            return(values);
        }
        public ContentItem CreateContentItem(Form form, IValueProvider valueProvider)
        {
            var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(form.FormBindingContentType);

            if (contentTypeDefinition == null)
            {
                return(null);
            }

            var contentItem = _contentManager.New(contentTypeDefinition.Name);

            // Create the version record before updating fields to prevent those field values from being lost when invoking Create.
            // If Create is invoked while VersionRecord is null, a new VersionRecord will be created, wiping out our field values.
            contentItem.VersionRecord = new ContentItemVersionRecord {
                ContentItemRecord = new ContentItemRecord(),
                Number            = 1,
                Latest            = true,
                Published         = true
            };

            var lookup       = _bindingManager.DescribeBindingsFor(contentTypeDefinition);
            var formElements = GetFormElements(form);

            foreach (var element in formElements)
            {
                var context = new ReadElementValuesContext {
                    ValueProvider = valueProvider
                };
                ReadElementValues(element, context);

                var value           = context.Output[element.Name];
                var bindingSettings = element.Data.GetModel <FormBindingSettings>();

                if (bindingSettings != null)
                {
                    foreach (var partBindingSettings in bindingSettings.Parts)
                    {
                        InvokePartBindings(contentItem, lookup, partBindingSettings, value);

                        foreach (var fieldBindingSettings in partBindingSettings.Fields)
                        {
                            InvokeFieldBindings(contentItem, lookup, partBindingSettings, fieldBindingSettings, value);
                        }
                    }
                }
            }

            var contentTypeSettings = contentTypeDefinition.Settings.GetModel <ContentTypeSettings>();

            _contentManager.Create(contentItem, VersionOptions.Draft);

            if (form.Publication == "Publish" || !contentTypeSettings.Draftable)
            {
                _contentManager.Publish(contentItem);
            }

            return(contentItem);
        }
        public override void GetElementValue(FormElement element, ReadElementValuesContext context) {
            var ipAddressField = element as IpAddressField;

            if (ipAddressField == null)
                return;

            var key = ipAddressField.Name;
            context.Output[key] = _clientHostAddressAccessor.GetClientAddress();
        }
        public override void GetElementValue(FormElement element, ReadElementValuesContext context)
        {
            var fileField = element as FileField;

            if (fileField == null)
                return;

            context.Output[fileField.Name] = fileField.PostedValue;
        }
        public override void GetElementValue(FormElement element, ReadElementValuesContext context) {
            var userNameField = element as UserNameField;

            if (userNameField == null)
                return;

            var key = userNameField.Name;
            var currentUser = _wca.GetContext().CurrentUser;
            context.Output[key] = currentUser != null ? currentUser.UserName : null;
        }
        public override void GetElementValue(FormElement element, ReadElementValuesContext context) {

            if (String.IsNullOrWhiteSpace(element.Name))
                return;

            var key = element.Name;
            var valueProviderResult = context.ValueProvider.GetValue(key);

            if (String.IsNullOrWhiteSpace(key) || valueProviderResult == null)
                return;

            var items = valueProviderResult.RawValue as string[];
            if (items == null)
                return;

            var combinedValues = String.Join(",", items);
            context.Output[key] = combinedValues;
            element.RuntimeValue = combinedValues;
            element.PostedValue = combinedValues;
        }
 public void ReadElementValues(FormElement element, ReadElementValuesContext context)
 {
     _elementHandlers.GetElementValue(element, context);
 }
 void IFormElementEventHandler.GetElementValue(FormElement element, ReadElementValuesContext context) { }
 public virtual void GetElementValue(FormElement element, ReadElementValuesContext context) {}
 public virtual void GetElementValue(FormElement element, ReadElementValuesContext context)
 {
 }