Search in sources :

Example 1 with PartComponent

use of com.enonic.xp.region.PartComponent 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 PartComponent

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

the class ProjectContentEventListenerTest method createPage.

private Page createPage() {
    PropertyTree componentConfig = new PropertyTree();
    componentConfig.setString("my-prop", "value");
    PartComponent component = PartComponent.create().descriptor(DescriptorKey.from("mainapplication:partTemplateName")).config(componentConfig).build();
    Region region = Region.create().name("my-region").add(component).build();
    PageRegions regions = PageRegions.create().add(region).build();
    PropertyTree pageConfig = new PropertyTree();
    pageConfig.setString("background-color", "blue");
    Mockito.when(partDescriptorService.getByKey(DescriptorKey.from("mainapplication:partTemplateName"))).thenReturn(PartDescriptor.create().key(DescriptorKey.from("mainapplication:partTemplateName")).displayName("my-component").config(Form.create().build()).build());
    return Page.create().template(PageTemplateKey.from("mypagetemplate")).regions(regions).build();
}
Also used : PageRegions(com.enonic.xp.page.PageRegions) PropertyTree(com.enonic.xp.data.PropertyTree) Region(com.enonic.xp.region.Region) PartComponent(com.enonic.xp.region.PartComponent)

Example 3 with PartComponent

use of com.enonic.xp.region.PartComponent 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 4 with PartComponent

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

the class PortalUrlServiceImpl_componentUrlTest method addComponent.

private void addComponent() {
    final PartComponent component = PartComponent.create().descriptor("myapp:mycomp").build();
    final Region region = Region.create().name("main").add(component).build();
    this.portalRequest.setComponent(component);
}
Also used : Region(com.enonic.xp.region.Region) PartComponent(com.enonic.xp.region.PartComponent)

Example 5 with PartComponent

use of com.enonic.xp.region.PartComponent 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

PartComponent (com.enonic.xp.region.PartComponent)11 PropertyTree (com.enonic.xp.data.PropertyTree)5 LayoutComponent (com.enonic.xp.region.LayoutComponent)5 PartDescriptor (com.enonic.xp.region.PartDescriptor)4 Test (org.junit.jupiter.api.Test)4 Form (com.enonic.xp.form.Form)3 Page (com.enonic.xp.page.Page)3 LayoutDescriptor (com.enonic.xp.region.LayoutDescriptor)3 EditableContent (com.enonic.xp.content.EditableContent)2 AbstractDescriptorServiceTest (com.enonic.xp.core.impl.content.page.AbstractDescriptorServiceTest)2 PageDescriptor (com.enonic.xp.page.PageDescriptor)2 Component (com.enonic.xp.region.Component)2 Region (com.enonic.xp.region.Region)2 PropertySet (com.enonic.xp.data.PropertySet)1 DescriptorKey (com.enonic.xp.page.DescriptorKey)1 PageRegions (com.enonic.xp.page.PageRegions)1 RegionDescriptors (com.enonic.xp.region.RegionDescriptors)1