Search in sources :

Example 16 with FormItem

use of com.enonic.xp.form.FormItem in project xp by enonic.

the class ContentTypeMapper method serializeFormItemSet.

private void serializeFormItemSet(final MapGenerator gen, final FormItemSet itemSet) {
    gen.map();
    gen.value("formItemType", "ItemSet");
    gen.value("name", itemSet.getName());
    gen.value("label", itemSet.getLabel());
    gen.value("customText", itemSet.getCustomText());
    gen.value("helpText", itemSet.getHelpText());
    serializeOccurrences(gen, itemSet.getOccurrences());
    gen.array("items");
    for (FormItem formItem : itemSet) {
        serializeItem(gen, formItem);
    }
    gen.end();
    gen.end();
}
Also used : FormItem(com.enonic.xp.form.FormItem)

Example 17 with FormItem

use of com.enonic.xp.form.FormItem in project xp by enonic.

the class ContentTypeMapper method serializeLayout.

private void serializeLayout(final MapGenerator gen, final FieldSet fieldSet) {
    gen.map();
    gen.value("formItemType", "Layout");
    gen.value("name", fieldSet.getName());
    gen.value("label", fieldSet.getLabel());
    gen.array("items");
    for (FormItem formItem : fieldSet) {
        serializeItem(gen, formItem);
    }
    gen.end();
    gen.end();
}
Also used : FormItem(com.enonic.xp.form.FormItem)

Example 18 with FormItem

use of com.enonic.xp.form.FormItem in project xp by enonic.

the class MacroInstruction method createContext.

private MacroContext createContext(final Instruction macroInstruction, final MacroDescriptor macroDescriptor, final PortalRequest request) {
    final Form macroForm = macroDescriptor.getForm();
    final Map<String, String> paramCaseTranslator = new HashMap<>(macroForm.size());
    for (FormItem formItem : macroForm) {
        final String name = formItem.getName();
        paramCaseTranslator.put(name.toLowerCase(), name);
    }
    final MacroContext.Builder context = MacroContext.create().name(macroDescriptor.getName());
    for (String name : macroInstruction.attributeNames()) {
        if (name.equalsIgnoreCase(MACRO_BODY) || name.equalsIgnoreCase(MACRO_NAME) || name.equalsIgnoreCase(MACRO_DOCUMENT)) {
            continue;
        }
        String contextParamName = name;
        if (macroForm.getFormItems().getItemByName(name) == null) {
            final String normalizedName = paramCaseTranslator.get(name.toLowerCase());
            if (normalizedName != null) {
                contextParamName = normalizedName;
            }
        }
        for (String attribute : macroInstruction.attributes(name)) {
            context.param(contextParamName, attribute);
        }
    }
    context.body(macroInstruction.attribute(MACRO_BODY));
    context.request(request);
    final String documentRef = macroInstruction.attribute(MACRO_DOCUMENT);
    final String document = (String) ContextAccessor.current().getLocalScope().getAttribute(documentRef);
    context.document(document);
    return context.build();
}
Also used : Form(com.enonic.xp.form.Form) HashMap(java.util.HashMap) FormItem(com.enonic.xp.form.FormItem) MacroContext(com.enonic.xp.portal.macro.MacroContext)

Aggregations

FormItem (com.enonic.xp.form.FormItem)18 Input (com.enonic.xp.form.Input)9 ContentType (com.enonic.xp.schema.content.ContentType)6 Test (org.junit.jupiter.api.Test)6 FormItemSet (com.enonic.xp.form.FormItemSet)5 FormOptionSet (com.enonic.xp.form.FormOptionSet)5 FieldSet (com.enonic.xp.form.FieldSet)4 FormOptionSetOption (com.enonic.xp.form.FormOptionSetOption)4 Form (com.enonic.xp.form.Form)3 ExtraData (com.enonic.xp.content.ExtraData)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 Occurrences (com.enonic.xp.form.Occurrences)2 InputTypeConfig (com.enonic.xp.inputtype.InputTypeConfig)2 XData (com.enonic.xp.schema.xdata.XData)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ExtraDatas (com.enonic.xp.content.ExtraDatas)1 PropertySet (com.enonic.xp.data.PropertySet)1 FormItems (com.enonic.xp.form.FormItems)1 InlineMixin (com.enonic.xp.form.InlineMixin)1