Search in sources :

Example 6 with LayoutComponent

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

the class PageDefaultValuesProcessor method applyRegionDefaultValues.

private void applyRegionDefaultValues(final Region region, final Region sourceRegion) {
    for (Component cmp : region.getComponents()) {
        if (!(cmp.getType() instanceof PartComponentType || cmp.getType() instanceof LayoutComponentType)) {
            // skip if not Part or Layout
            continue;
        }
        final DescriptorBasedComponent layoutOrPart = (DescriptorBasedComponent) cmp;
        final PropertyTree cmpData = layoutOrPart.getConfig();
        final Component sourceCmp = sourceRegion != null ? sourceRegion.getComponents().stream().filter(c -> c.equals(cmp)).findFirst().orElse(null) : null;
        if (sourceCmp == null && cmpData.getRoot().getPropertySize() == 0) {
            applyComponentDefaultValues(layoutOrPart);
        }
        // layout regions
        if (cmp.getType() instanceof LayoutComponentType) {
            final LayoutComponent layout = (LayoutComponent) cmp;
            final LayoutComponent sourceLayout = (LayoutComponent) sourceCmp;
            for (Region layoutRegion : layout.getRegions()) {
                final Region sourceLayoutRegion = sourceLayout != null ? sourceLayout.getRegion(region.getName()) : null;
                applyRegionDefaultValues(layoutRegion, sourceLayoutRegion);
            }
        }
    }
}
Also used : PartComponentType(com.enonic.xp.region.PartComponentType) FormDefaultValuesProcessor(com.enonic.xp.form.FormDefaultValuesProcessor) PartDescriptorService(com.enonic.xp.region.PartDescriptorService) PageDescriptor(com.enonic.xp.page.PageDescriptor) Page(com.enonic.xp.page.Page) LayoutDescriptorService(com.enonic.xp.region.LayoutDescriptorService) PartDescriptor(com.enonic.xp.region.PartDescriptor) LayoutComponentType(com.enonic.xp.region.LayoutComponentType) DescriptorBasedComponent(com.enonic.xp.region.DescriptorBasedComponent) LayoutDescriptor(com.enonic.xp.region.LayoutDescriptor) Objects(java.util.Objects) Form(com.enonic.xp.form.Form) Region(com.enonic.xp.region.Region) PageDescriptorService(com.enonic.xp.page.PageDescriptorService) LayoutComponent(com.enonic.xp.region.LayoutComponent) PartComponentType(com.enonic.xp.region.PartComponentType) PartComponent(com.enonic.xp.region.PartComponent) Component(com.enonic.xp.region.Component) PropertyTree(com.enonic.xp.data.PropertyTree) PropertyTree(com.enonic.xp.data.PropertyTree) Region(com.enonic.xp.region.Region) DescriptorBasedComponent(com.enonic.xp.region.DescriptorBasedComponent) LayoutComponent(com.enonic.xp.region.LayoutComponent) PartComponent(com.enonic.xp.region.PartComponent) Component(com.enonic.xp.region.Component) LayoutComponentType(com.enonic.xp.region.LayoutComponentType) DescriptorBasedComponent(com.enonic.xp.region.DescriptorBasedComponent) LayoutComponent(com.enonic.xp.region.LayoutComponent)

Example 7 with LayoutComponent

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

the class ComponentServiceTest method testGetLayoutByKey.

@Test
public void testGetLayoutByKey() throws Exception {
    final Component layout1App1 = this.service.getByKey(DescriptorKey.from("myapp1:mylayout"));
    final Component layout1App2 = this.service.getByKey(DescriptorKey.from("myapp2:mylayout"));
    assertNotNull(layout1App1);
    assertNotNull(layout1App2);
    assertTrue(layout1App1 instanceof LayoutComponent);
    assertTrue(layout1App2 instanceof LayoutComponent);
}
Also used : LayoutComponent(com.enonic.xp.region.LayoutComponent) PartComponent(com.enonic.xp.region.PartComponent) Component(com.enonic.xp.region.Component) LayoutComponent(com.enonic.xp.region.LayoutComponent) Test(org.junit.jupiter.api.Test) AbstractDescriptorServiceTest(com.enonic.xp.core.impl.content.page.AbstractDescriptorServiceTest)

Example 8 with LayoutComponent

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

the class ComponentServiceTest method testGetLayoutByName.

@Test
public void testGetLayoutByName() throws Exception {
    final Component layout1App1 = this.service.getByName(ApplicationKey.from("myapp1"), ComponentName.from("mylayout"));
    final Component layout1App2 = this.service.getByName(ApplicationKey.from("myapp2"), ComponentName.from("mylayout"));
    assertNotNull(layout1App1);
    assertNotNull(layout1App2);
    assertTrue(layout1App1 instanceof LayoutComponent);
    assertTrue(layout1App2 instanceof LayoutComponent);
}
Also used : LayoutComponent(com.enonic.xp.region.LayoutComponent) PartComponent(com.enonic.xp.region.PartComponent) Component(com.enonic.xp.region.Component) LayoutComponent(com.enonic.xp.region.LayoutComponent) Test(org.junit.jupiter.api.Test) AbstractDescriptorServiceTest(com.enonic.xp.core.impl.content.page.AbstractDescriptorServiceTest)

Example 9 with LayoutComponent

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

the class PageRegionsConfigProcessorTest method processPage.

private PatternIndexConfigDocument processPage(final Page page, final ListIterator<Form> partForms, final ListIterator<Form> layoutForms) {
    final RegionDescriptors.Builder regionDescriptorsBuilder = RegionDescriptors.create();
    page.getRegions().forEach(region -> {
        region.getComponents().forEach(component -> {
            if (PartComponentType.INSTANCE == component.getType()) {
                if (partForms != null && partForms.hasNext()) {
                    final PartComponent partComponent = (PartComponent) component;
                    Mockito.when(partDescriptorService.getByKey(partComponent.getDescriptor())).thenReturn(PartDescriptor.create().key(partComponent.getDescriptor()).config(partForms.next()).build());
                }
            } else if (LayoutComponentType.INSTANCE == component.getType()) {
                if (layoutForms != null && layoutForms.hasNext()) {
                    final LayoutComponent layoutComponent = (LayoutComponent) component;
                    Mockito.when(layoutDescriptorService.getByKey(layoutComponent.getDescriptor())).thenReturn(LayoutDescriptor.create().key(layoutComponent.getDescriptor()).config(layoutForms.next()).regions(RegionDescriptors.create().build()).build());
                    if (layoutComponent.hasRegions()) {
                        processLayoutRegions(layoutComponent.getRegions(), partForms);
                    }
                }
            }
        });
        regionDescriptorsBuilder.add(RegionDescriptor.create().name(region.getName()).build());
    });
    final PageRegionsConfigProcessor configProcessor = new PageRegionsConfigProcessor(page, partDescriptorService, layoutDescriptorService);
    return configProcessor.processDocument(PatternIndexConfigDocument.create()).build();
}
Also used : RegionDescriptors(com.enonic.xp.region.RegionDescriptors) PartComponent(com.enonic.xp.region.PartComponent) LayoutComponent(com.enonic.xp.region.LayoutComponent)

Example 10 with LayoutComponent

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

the class ComponentInstruction method resolveComponentInFragment.

private Component resolveComponentInFragment(final Page page, final ComponentPath path) {
    final Component fragmentComponent = page.getFragment();
    if (!(fragmentComponent instanceof LayoutComponent)) {
        throw new RenderException("Component not found: [{0}]", path);
    }
    final LayoutComponent layout = (LayoutComponent) fragmentComponent;
    final LayoutRegions pageRegions = layout.getRegions();
    final Component component = pageRegions.getComponent(path);
    if (component == null) {
        throw new RenderException("Component not found: [{0}]", path);
    }
    return component;
}
Also used : RenderException(com.enonic.xp.portal.impl.rendering.RenderException) LayoutComponent(com.enonic.xp.region.LayoutComponent) Component(com.enonic.xp.region.Component) LayoutComponent(com.enonic.xp.region.LayoutComponent) LayoutRegions(com.enonic.xp.region.LayoutRegions)

Aggregations

LayoutComponent (com.enonic.xp.region.LayoutComponent)12 Component (com.enonic.xp.region.Component)6 PartComponent (com.enonic.xp.region.PartComponent)6 LayoutDescriptor (com.enonic.xp.region.LayoutDescriptor)4 Page (com.enonic.xp.page.Page)3 LayoutRegions (com.enonic.xp.region.LayoutRegions)3 PartDescriptor (com.enonic.xp.region.PartDescriptor)3 Test (org.junit.jupiter.api.Test)3 AbstractDescriptorServiceTest (com.enonic.xp.core.impl.content.page.AbstractDescriptorServiceTest)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 Form (com.enonic.xp.form.Form)2 DescriptorKey (com.enonic.xp.page.DescriptorKey)2 PageDescriptor (com.enonic.xp.page.PageDescriptor)2 Region (com.enonic.xp.region.Region)2 Content (com.enonic.xp.content.Content)1 EditableContent (com.enonic.xp.content.EditableContent)1 IndexConfigVisitor (com.enonic.xp.core.impl.content.index.IndexConfigVisitor)1 PropertySet (com.enonic.xp.data.PropertySet)1 FormDefaultValuesProcessor (com.enonic.xp.form.FormDefaultValuesProcessor)1 PageDescriptorService (com.enonic.xp.page.PageDescriptorService)1