Search in sources :

Example 1 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)

Example 2 with ContentType

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

the class CreateContentHandlerTest method createContentAutoGenerateNameWithExistingName.

@Test
public void createContentAutoGenerateNameWithExistingName() throws Exception {
    when(this.contentService.create(any(CreateContentParams.class))).thenAnswer(mock -> createContent((CreateContentParams) mock.getArguments()[0]));
    when(this.contentService.contentExists(Mockito.eq(ContentPath.from("/a/b/my-content")))).thenReturn(true);
    when(this.contentService.contentExists(Mockito.eq(ContentPath.from("/a/b/my-content-1")))).thenReturn(true);
    when(this.contentService.contentExists(Mockito.eq(ContentPath.from("/a/b/my-content-2")))).thenReturn(true);
    final ContentType contentType = ContentType.create().name("test:myContentType").superType(ContentTypeName.structured()).build();
    GetContentTypeParams getContentType = GetContentTypeParams.from(ContentTypeName.from("test:myContentType"));
    when(this.contentTypeService.getByName(Mockito.eq(getContentType))).thenReturn(contentType);
    runFunction("/test/CreateContentHandlerTest.js", "createContentAutoGenerateNameWithExistingName");
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ContentType(com.enonic.xp.schema.content.ContentType) CreateContentParams(com.enonic.xp.content.CreateContentParams) Test(org.junit.jupiter.api.Test)

Example 3 with ContentType

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

the class HtmlAreaContentProcessor method processUpdate.

@Override
public ProcessUpdateResult processUpdate(final ProcessUpdateParams params) {
    final CreateAttachments createAttachments = params.getCreateAttachments();
    final ContentEditor editor;
    editor = editable -> {
        final ContentIds.Builder processedIds = ContentIds.create();
        final ContentType contentType = contentTypeService.getByName(GetContentTypeParams.from(editable.source.getType()));
        processContentData(editable.data, contentType, processedIds);
        processExtraData(editable.extraDatas, processedIds);
        processPageData(editable.page, processedIds);
        if (editable instanceof EditableSite) {
            processSiteConfigData(((EditableSite) editable).siteConfigs, processedIds);
        }
        editable.processedReferences = processedIds;
    };
    return new ProcessUpdateResult(createAttachments, editor);
}
Also used : CreateAttachments(com.enonic.xp.attachment.CreateAttachments) ContentEditor(com.enonic.xp.content.ContentEditor) ContentType(com.enonic.xp.schema.content.ContentType) EditableSite(com.enonic.xp.content.EditableSite) ContentIds(com.enonic.xp.content.ContentIds) ProcessUpdateResult(com.enonic.xp.content.processor.ProcessUpdateResult)

Example 4 with ContentType

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

the class HtmlAreaContentProcessorTest method site_config_data.

@Test
public void site_config_data() throws IOException {
    final ContentType contentType = ContentType.create().name(ContentTypeName.site()).superType(ContentTypeName.folder()).form(Form.create().build()).build();
    Mockito.when(contentTypeService.getByName(GetContentTypeParams.from(contentType.getName()))).thenReturn(contentType);
    Mockito.when(siteService.getDescriptor(ApplicationKey.SYSTEM)).thenReturn(SiteDescriptor.create().form(Form.create().addFormItem(Input.create().name("htmlData").label("htmlData").inputType(InputTypeName.HTML_AREA).build()).build()).build());
    final PropertyTree data = new PropertyTree();
    data.addProperty("htmlData", ValueFactory.newString("<img alt=\"Dictyophorus_spumans01.jpg\" data-src=\"image://image-id\"/>"));
    final EditableSite editableSite = new EditableSite(Site.create().name("myContentName").type(ContentTypeName.site()).parentPath(ContentPath.ROOT).data(new PropertyTree()).siteConfigs(SiteConfigs.create().add(SiteConfig.create().config(data).application(ApplicationKey.SYSTEM).build()).build()).build());
    result.getEditor().edit(editableSite);
    assertEquals(1, editableSite.processedReferences.build().getSize());
    assertTrue(editableSite.processedReferences.build().contains(ContentId.from("image-id")));
}
Also used : ContentType(com.enonic.xp.schema.content.ContentType) EditableSite(com.enonic.xp.content.EditableSite) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 5 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)

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