<commit_before>﻿using System.Collections.Generic;
using Orchard.DynamicForms.Elements;
using Orchard.Layouts.Framework.Display;
using Orchard.Layouts.Framework.Drivers;
using Orchard.Layouts.Helpers;
using Orchard.Layouts.Services;
using Orchard.Tokens;
using DescribeContext = Orchard.Forms.Services.DescribeContext;

namespace Orchard.DynamicForms.Drivers {
    public class HiddenFieldElementDriver : FormsElementDriver<HiddenField> {
        private readonly ITokenizer _tokenizer;
        public HiddenFieldElementDriver(IFormsBasedElementServices formsServices, ITokenizer tokenizer) : base(formsServices) {
            _tokenizer = tokenizer;
        }

        protected override IEnumerable<string> FormNames {
            get { yield return "HiddenField"; }
        }

        protected override void DescribeForm(DescribeContext context) {
            context.Form("HiddenField", factory => {
                var shape = (dynamic)factory;
                var form = shape.Fieldset(
                    Id: "HiddenField",
                    _Span: shape.Textbox(
                        Id: "Value",
                        Name: "Value",
                        Title: "Value",
                        Classes: new[] { "text", "medium" },
                        Description: T("The value of this hidden field.")));

                return form;
            });
        }

        protected override void OnDisplaying(HiddenField element, ElementDisplayingContext context) {
            context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, context.GetTokenData());
            context.ElementShape.ProcessedValue = element.RuntimeValue;
        }
    }
}<commit_msg>Fixes #7120 Hidden Field in Dynamic Forms causes crash (#7123)<commit_after>﻿using System.Collections.Generic;
using Orchard.DynamicForms.Elements;
using Orchard.Layouts.Framework.Display;
using Orchard.Layouts.Framework.Drivers;
using Orchard.Layouts.Helpers;
using Orchard.Layouts.Services;
using Orchard.Tokens;
using DescribeContext = Orchard.Forms.Services.DescribeContext;

namespace Orchard.DynamicForms.Drivers {
    public class HiddenFieldElementDriver : FormsElementDriver<HiddenField> {
        private readonly ITokenizer _tokenizer;
        public HiddenFieldElementDriver(IFormsBasedElementServices formsServices, ITokenizer tokenizer) : base(formsServices) {
            _tokenizer = tokenizer;
        }

        protected override IEnumerable<string> FormNames {
            get { yield return "HiddenField"; }
        }

        protected override void DescribeForm(DescribeContext context) {
            context.Form("HiddenField", factory => {
                var shape = (dynamic)factory;
                var form = shape.Fieldset(
                    Id: "HiddenField",
                    _Span: shape.Textbox(
                        Id: "Value",
                        Name: "Value",
                        Title: "Value",
                        Classes: new[] { "text", "medium" },
                        Description: T("The value of this hidden field.")));

                return form;
            });
        }

        protected override void OnDisplaying(HiddenField element, ElementDisplayingContext context) {
            context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, context.GetTokenData());
            context.ElementShape.ProcessedValue = element.RuntimeValue ?? string.Empty;
        }
    }
}
{'fraction_non_alphanumeric': 0.085383502170767, 'fraction_numerical': 0.0023154848046309695, 'mean_word_length': 2.319884726224784, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '379395', 'n_tokens_mistral': 872, 'n_tokens_neox': 817, 'n_words': 192}