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