Exemplo n.º 1
0
 /// <summary>
 /// Generate a default form for the given resource type.
 /// </summary>
 public static EntityData GenerateDefaultFormForResourceType(EntityRef typeRef, bool isInDesignMode)
 {
     using (Profiler.Measure("GenerateDefaultFormForResourceType"))
         using (new EntitySnapshotContext())
             using (new SecurityBypassContext())
                 using (var generator = new DefaultLayoutGenerator(CurrentUiContext.Html, typeRef, isInDesignMode))
                 {
                     string request = CustomEditFormHelper.GetHtmlFormQuery(isInDesignMode);
                     return(generator.GetLayoutAsEntityData(request));
                 }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a form entity for a given type.
        /// </summary>
        /// <param name="alias">The alias given to the form.</param>
        /// <param name="name">The name given to the form.</param>
        /// <param name="description">The description given to the form.</param>
        /// <param name="type">The type to create the form for.</param>
        /// <param name="isDefault">Whether the form should be the default for the type.</param>
        /// <returns>The created form entity.</returns>
        public static CustomEditForm CreateForm(string alias, string name, string description, EntityType type, bool isDefault)
        {
            var generator      = new DefaultLayoutGenerator(CurrentUiContext.Html, new EntityRef(type), false);
            var formEntityData = generator.GetLayoutAsEntityData(FormQuery);

            var form = new EntityInfoService().CreateEntity(formEntityData).Entity.AsWritable <CustomEditForm>();

            form.Alias       = alias;
            form.Name        = name;
            form.Description = description;
            if (isDefault)
            {
                form.IsDefaultForEntityType = type;
            }

            return(form);
        }