Search in sources :

Example 1 with PartDescriptor

use of com.enonic.xp.region.PartDescriptor in project xp by enonic.

the class HtmlAreaContentProcessorTest method component_config_data.

@Test
public void component_config_data() throws IOException {
    final PropertyTree data = new PropertyTree();
    data.addProperty("htmlData", ValueFactory.newString("<img data-src=\"image://image-id\"/>"));
    final Form form = Form.create().addFormItem(Input.create().name("htmlData").label("htmlData").inputType(InputTypeName.HTML_AREA).build()).build();
    final PartDescriptor partDescriptor = PartDescriptor.create().key(DescriptorKey.from("app:part")).config(form).build();
    Mockito.when(partDescriptorService.getByKey(partDescriptor.getKey())).thenReturn(partDescriptor);
    final PartComponent partComponent = PartComponent.create().descriptor("myapp:part").descriptor(partDescriptor.getKey()).config(data).build();
    final PageDescriptor pageDescriptor = PageDescriptor.create().regions(RegionDescriptors.create().add(RegionDescriptor.create().name("region").build()).build()).key(DescriptorKey.from("app:page")).config(Form.create().build()).build();
    Mockito.when(pageDescriptorService.getByKey(pageDescriptor.getKey())).thenReturn(pageDescriptor);
    final Page page = Page.create().config(new PropertyTree()).descriptor(pageDescriptor.getKey()).regions(PageRegions.create().add(Region.create().name("region").add(partComponent).build()).build()).build();
    final EditableContent editableContent = new EditableContent(Media.create().name("myContentName").type(contentTypeName).page(page).parentPath(ContentPath.ROOT).data(new PropertyTree()).build());
    result.getEditor().edit(editableContent);
    assertEquals(1, editableContent.processedReferences.build().getSize());
    assertTrue(editableContent.processedReferences.build().contains(ContentId.from("image-id")));
}
Also used : PageDescriptor(com.enonic.xp.page.PageDescriptor) Form(com.enonic.xp.form.Form) PartDescriptor(com.enonic.xp.region.PartDescriptor) PropertyTree(com.enonic.xp.data.PropertyTree) EditableContent(com.enonic.xp.content.EditableContent) Page(com.enonic.xp.page.Page) PartComponent(com.enonic.xp.region.PartComponent) Test(org.junit.jupiter.api.Test)

Example 2 with PartDescriptor

use of com.enonic.xp.region.PartDescriptor in project xp by enonic.

the class HtmlAreaContentProcessor method processComponent.

private void processComponent(final DescriptorBasedComponent component, final ContentIds.Builder processedIds) {
    if (component.hasDescriptor()) {
        if (component instanceof LayoutComponent) {
            final LayoutDescriptor layoutDescriptor = this.layoutDescriptorService.getByKey(component.getDescriptor());
            if (layoutDescriptor != null) {
                processComponentDescriptor(component, layoutDescriptor, processedIds);
            }
            final LayoutComponent layoutComponent = (LayoutComponent) component;
            if (layoutComponent.hasRegions()) {
                processRegionsData(layoutComponent.getRegions(), processedIds);
            }
        }
        if (component instanceof PartComponent) {
            final PartDescriptor partDescriptor = this.partDescriptorService.getByKey(component.getDescriptor());
            if (partDescriptor != null) {
                processComponentDescriptor(component, partDescriptor, processedIds);
            }
        }
    }
}
Also used : LayoutDescriptor(com.enonic.xp.region.LayoutDescriptor) PartDescriptor(com.enonic.xp.region.PartDescriptor) PartComponent(com.enonic.xp.region.PartComponent) LayoutComponent(com.enonic.xp.region.LayoutComponent)

Example 3 with PartDescriptor

use of com.enonic.xp.region.PartDescriptor in project xp by enonic.

the class XmlPartDescriptorParserTest method assertResult.

private void assertResult() throws Exception {
    final PartDescriptor result = this.builder.build();
    assertEquals("myapplication:mypart", result.getKey().toString());
    assertEquals("mypart", result.getName());
    assertEquals("A Part", result.getDisplayName());
    assertEquals("key.display-name", result.getDisplayNameI18nKey());
    assertEquals("My Part Description", result.getDescription());
    assertEquals("key.description", result.getDescriptionI18nKey());
    final Form config = result.getConfig();
    assertNotNull(config);
    assertEquals(InputTypeName.DOUBLE, config.getFormItem("width").toInput().getInputType());
    assertEquals("Column width", config.getFormItem("width").toInput().getLabel());
    assertEquals("key.label", config.getFormItem("width").toInput().getLabelI18nKey());
    assertEquals("key.help-text", config.getFormItem("width").toInput().getHelpTextI18nKey());
    assertEquals("link-urls", config.getFormItem("link-urls").toInlineMixin().getName());
}
Also used : PartDescriptor(com.enonic.xp.region.PartDescriptor) Form(com.enonic.xp.form.Form)

Example 4 with PartDescriptor

use of com.enonic.xp.region.PartDescriptor in project xp by enonic.

the class ApplicationInfoServiceImplTest method mockPartDescriptors.

private void mockPartDescriptors(final ApplicationKey applicationKey) {
    final PartDescriptor partDescriptor1 = PartDescriptor.create().displayName("News part").config(Form.create().build()).key(DescriptorKey.from("module:new-part")).build();
    final PartDescriptor partDescriptor2 = PartDescriptor.create().displayName("News part2").config(Form.create().build()).key(DescriptorKey.from("module:new-part2")).build();
    Mockito.when(partDescriptorService.getByApplication(applicationKey)).thenReturn(PartDescriptors.from(partDescriptor1, partDescriptor2));
}
Also used : PartDescriptor(com.enonic.xp.region.PartDescriptor)

Example 5 with PartDescriptor

use of com.enonic.xp.region.PartDescriptor in project xp by enonic.

the class PageDefaultValuesProcessor method applyComponentDefaultValues.

private void applyComponentDefaultValues(final DescriptorBasedComponent cmp) {
    if (cmp.getDescriptor() == null) {
        return;
    }
    final Form cmpForm;
    if (cmp instanceof PartComponent) {
        final PartDescriptor partDescriptor = partDescriptorService.getByKey(cmp.getDescriptor());
        cmpForm = partDescriptor.getConfig();
    } else {
        final LayoutDescriptor layoutDescriptor = layoutDescriptorService.getByKey(cmp.getDescriptor());
        cmpForm = layoutDescriptor.getConfig();
    }
    if (cmpForm != null) {
        final PropertyTree cmpData = cmp.getConfig();
        formDefaultValuesProcessor.setDefaultValues(cmpForm, cmpData);
    }
}
Also used : LayoutDescriptor(com.enonic.xp.region.LayoutDescriptor) Form(com.enonic.xp.form.Form) PartDescriptor(com.enonic.xp.region.PartDescriptor) PropertyTree(com.enonic.xp.data.PropertyTree) PartComponent(com.enonic.xp.region.PartComponent)

Aggregations

PartDescriptor (com.enonic.xp.region.PartDescriptor)13 Test (org.junit.jupiter.api.Test)7 Form (com.enonic.xp.form.Form)5 LayoutDescriptor (com.enonic.xp.region.LayoutDescriptor)5 PartComponent (com.enonic.xp.region.PartComponent)4 PropertyTree (com.enonic.xp.data.PropertyTree)3 PortalRequest (com.enonic.xp.portal.PortalRequest)3 ControllerScript (com.enonic.xp.portal.controller.ControllerScript)3 ControllerScriptFactory (com.enonic.xp.portal.controller.ControllerScriptFactory)3 PartDescriptorService (com.enonic.xp.region.PartDescriptorService)3 WebSocketEvent (com.enonic.xp.web.websocket.WebSocketEvent)3 EditableContent (com.enonic.xp.content.EditableContent)2 Page (com.enonic.xp.page.Page)2 PageDescriptor (com.enonic.xp.page.PageDescriptor)2 PortalResponseSerializer (com.enonic.xp.portal.impl.controller.PortalResponseSerializer)2 LayoutComponent (com.enonic.xp.region.LayoutComponent)2 AbstractDescriptorServiceTest (com.enonic.xp.core.impl.content.page.AbstractDescriptorServiceTest)1 DescriptorKey (com.enonic.xp.page.DescriptorKey)1