Search in sources :

Example 21 with ContentType

use of com.enonic.xp.schema.content.ContentType in project xp by enonic.

the class XmlContentTypeParserTest method testI18nParse.

@Test
public void testI18nParse() throws Exception {
    parse(this.parser, "-i18n.xml");
    final ContentType result = this.builder.build();
    assertEquals("translated.display-name", result.getDisplayNameI18nKey());
    assertEquals("translated.description", result.getDescriptionI18nKey());
    assertEquals("translated.displayNameLabel", result.getDisplayNameLabelI18nKey());
}
Also used : ContentType(com.enonic.xp.schema.content.ContentType) Test(org.junit.jupiter.api.Test)

Example 22 with ContentType

use of com.enonic.xp.schema.content.ContentType in project xp by enonic.

the class XmlContentTypeParserTest method testI18n_itemSet.

@Test
public void testI18n_itemSet() throws Exception {
    parse(this.parser, "-i18n.xml");
    final ContentType result = this.builder.build();
    final FormItem item = result.getForm().getFormItem("item-set");
    assertNotNull(item);
    final FormItemSet formItemSet = (FormItemSet) item;
    assertEquals("translated.label", formItemSet.getLabelI18nKey());
    assertEquals("translated.help-text", formItemSet.getHelpTextI18nKey());
    final Input inputInsideFormItemSet = formItemSet.getFormItems().getInput(FormItemPath.from("textLine1"));
    assertEquals("translated.help-text", inputInsideFormItemSet.getHelpTextI18nKey());
    assertEquals("translated.label", inputInsideFormItemSet.getLabelI18nKey());
}
Also used : Input(com.enonic.xp.form.Input) ContentType(com.enonic.xp.schema.content.ContentType) FormItem(com.enonic.xp.form.FormItem) FormItemSet(com.enonic.xp.form.FormItemSet) Test(org.junit.jupiter.api.Test)

Example 23 with ContentType

use of com.enonic.xp.schema.content.ContentType in project xp by enonic.

the class XmlContentTypeParserTest method testI18nParseOmittingElementValue.

@Test
public void testI18nParseOmittingElementValue() throws Exception {
    parse(this.parser, "-i18n-only-attribute.xml");
    final ContentType result = this.builder.build();
    assertEquals("translated.display-name", result.getDisplayNameI18nKey());
    assertEquals("translated.description", result.getDescriptionI18nKey());
    // input type
    final Input input = (Input) result.getForm().getFormItem("textLine");
    assertEquals("translated.label", input.getLabelI18nKey());
    assertEquals("translated.label", input.getLabel());
    assertEquals("translated.help-text", input.getHelpTextI18nKey());
    assertEquals("translated.help-text", input.getHelpText());
    // option set
    final FormItem item = result.getForm().getFormItem("radioOptionSet");
    assertNotNull(item);
    final FormOptionSet radioOptionSet = (FormOptionSet) item;
    assertEquals(FormItemType.FORM_OPTION_SET, radioOptionSet.getType());
    assertEquals("translated.help-text", radioOptionSet.getHelpTextI18nKey());
    assertEquals("translated.help-text", radioOptionSet.getHelpText());
    assertEquals("translated.label", radioOptionSet.getLabelI18nKey());
    assertEquals("translated.label", radioOptionSet.getLabel());
    final Input inputInsideOption = radioOptionSet.getFormItems().getInput(FormItemPath.from("option_1.text-input"));
    assertEquals("translated.help-text", inputInsideOption.getHelpTextI18nKey());
    assertEquals("translated.help-text", inputInsideOption.getHelpText());
    assertEquals("translated.label", inputInsideOption.getLabelI18nKey());
    assertEquals("translated.label", inputInsideOption.getLabel());
    final FormOptionSetOption radioOption = radioOptionSet.getFormItems().getItemByName("option_1").toFormOptionSetOption();
    assertEquals("translated.help-text", radioOption.getHelpTextI18nKey());
    assertEquals("translated.help-text", radioOption.getHelpText());
    assertEquals("translated.label", radioOption.getLabelI18nKey());
    assertEquals("translated.label", radioOption.getLabel());
    // field set
    FormItem fieldSetItem = null;
    for (final FormItem next : result.getForm().getFormItems()) {
        if (next.getName().startsWith("fieldSet")) {
            fieldSetItem = next;
        }
    }
    assertNotNull(fieldSetItem);
    final FieldSet fieldSet = (FieldSet) fieldSetItem;
    assertEquals("translated.label", fieldSet.getLabelI18nKey());
    assertEquals("translated.label", fieldSet.getLabel());
    final Input inputInsideFieldSet = fieldSet.getFormItems().getInput(FormItemPath.from("textLine2"));
    assertEquals("translated.help-text", inputInsideFieldSet.getHelpTextI18nKey());
    assertEquals("translated.help-text", inputInsideFieldSet.getHelpText());
    assertEquals("translated.label", inputInsideFieldSet.getLabelI18nKey());
    assertEquals("translated.label", inputInsideFieldSet.getLabel());
    // item set
    final FormItem itemSet = result.getForm().getFormItem("item-set");
    assertNotNull(item);
    final FormItemSet formItemSet = (FormItemSet) itemSet;
    assertEquals("translated.label", formItemSet.getLabelI18nKey());
    assertEquals("translated.label", formItemSet.getLabel());
    assertEquals("translated.help-text", formItemSet.getHelpTextI18nKey());
    assertEquals("translated.help-text", formItemSet.getHelpText());
    final Input inputInsideFormItemSet = formItemSet.getFormItems().getInput(FormItemPath.from("textLine1"));
    assertEquals("translated.help-text", inputInsideFormItemSet.getHelpTextI18nKey());
    assertEquals("translated.help-text", inputInsideFormItemSet.getHelpText());
    assertEquals("translated.label", inputInsideFormItemSet.getLabelI18nKey());
    assertEquals("translated.label", inputInsideFormItemSet.getLabel());
}
Also used : FormOptionSet(com.enonic.xp.form.FormOptionSet) Input(com.enonic.xp.form.Input) FieldSet(com.enonic.xp.form.FieldSet) ContentType(com.enonic.xp.schema.content.ContentType) FormItem(com.enonic.xp.form.FormItem) FormOptionSetOption(com.enonic.xp.form.FormOptionSetOption) FormItemSet(com.enonic.xp.form.FormItemSet) Test(org.junit.jupiter.api.Test)

Example 24 with ContentType

use of com.enonic.xp.schema.content.ContentType in project xp by enonic.

the class ContentTypeHandler method inlineMixins.

private ContentType inlineMixins(final ContentType contentType) {
    final ContentType.Builder ctInlined = ContentType.create(contentType);
    final Form inlinedForm = mixinService.get().inlineFormItems(contentType.getForm());
    if (inlinedForm == null) {
        return contentType;
    }
    return ctInlined.form(inlinedForm).build();
}
Also used : ContentType(com.enonic.xp.schema.content.ContentType) Form(com.enonic.xp.form.Form)

Example 25 with ContentType

use of com.enonic.xp.schema.content.ContentType in project xp by enonic.

the class ContentTypeHandler method getContentType.

public ContentTypeMapper getContentType() {
    if (name == null || name.isBlank()) {
        return null;
    }
    final GetContentTypeParams params = GetContentTypeParams.from(ContentTypeName.from(name));
    final ContentType ctype = contentTypeService.get().getByName(params);
    return ctype == null ? null : new ContentTypeMapper(inlineMixins(ctype));
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ContentType(com.enonic.xp.schema.content.ContentType) ContentTypeMapper(com.enonic.xp.lib.content.mapper.ContentTypeMapper)

Aggregations

ContentType (com.enonic.xp.schema.content.ContentType)56 Test (org.junit.jupiter.api.Test)35 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)28 Content (com.enonic.xp.content.Content)12 CreateContentParams (com.enonic.xp.content.CreateContentParams)10 ValidationErrors (com.enonic.xp.content.ValidationErrors)9 Form (com.enonic.xp.form.Form)8 PropertyTree (com.enonic.xp.data.PropertyTree)7 Input (com.enonic.xp.form.Input)7 FormItem (com.enonic.xp.form.FormItem)6 FieldSet (com.enonic.xp.form.FieldSet)5 FormItemSet (com.enonic.xp.form.FormItemSet)5 ContentTypes (com.enonic.xp.schema.content.ContentTypes)5 AbstractSchemaTest (com.enonic.xp.core.impl.schema.AbstractSchemaTest)4 EditableSite (com.enonic.xp.content.EditableSite)3 PropertySet (com.enonic.xp.data.PropertySet)3 FormOptionSet (com.enonic.xp.form.FormOptionSet)3 FormOptionSetOption (com.enonic.xp.form.FormOptionSetOption)3 XData (com.enonic.xp.schema.xdata.XData)3 ApplicationKey (com.enonic.xp.app.ApplicationKey)2