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));
}
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");
}
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);
}
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")));
}
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();
}
Aggregations