use of com.enonic.xp.region.LayoutRegions in project xp by enonic.
the class TestDataFixtures method createLayoutComponent.
private static LayoutComponent createLayoutComponent() {
final Region region1 = Region.create().name("left").add(PartComponent.create().build()).add(TextComponent.create().text("text text text").build()).add(TextComponent.create().build()).build();
final Region region2 = Region.create().name("right").add(createImageComponent("image-id", "Some Image", null)).add(createFragmentComponent("213sda-ss222", "My Fragment")).build();
final LayoutRegions layoutRegions = LayoutRegions.create().add(region1).add(region2).build();
return LayoutComponent.create().descriptor("layoutDescriptor:name").regions(layoutRegions).build();
}
use of com.enonic.xp.region.LayoutRegions in project xp by enonic.
the class PageDataSerializerTest method createLayoutComponent.
private LayoutComponent createLayoutComponent() {
final String layoutName = "MyLayout";
final DescriptorKey layoutDescriptorKey = DescriptorKey.from("layoutDescriptor:name");
final String regionName1 = "left";
final String regionName2 = "right";
final Region region1 = Region.create().name(regionName1).add(PartComponent.create().build()).add(TextComponent.create().text("text text text").build()).add(TextComponent.create().build()).build();
final Region region2 = Region.create().name(regionName2).add(createImageComponent("image-id", "Some Image", null)).add(createFragmentComponent("213sda-ss222", "My Fragment")).build();
final LayoutRegions layoutRegions = LayoutRegions.create().add(region1).add(region2).build();
Mockito.when(layoutDescriptorService.getByKey(layoutDescriptorKey)).thenReturn(LayoutDescriptor.create().key(layoutDescriptorKey).displayName(layoutName).config(Form.create().build()).regions(RegionDescriptors.create().add(RegionDescriptor.create().name(regionName1).build()).add(RegionDescriptor.create().name(regionName2).build()).build()).build());
return LayoutComponent.create().descriptor(layoutDescriptorKey).regions(layoutRegions).build();
}
use of com.enonic.xp.region.LayoutRegions 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;
}
use of com.enonic.xp.region.LayoutRegions in project xp by enonic.
the class FragmentPageResolver method replaceComponentInPage.
private PageRegions replaceComponentInPage(final PageRegions pageRegions, final ImmutableList<ComponentPath.RegionAndComponent> pathItems, final Component component) {
final ComponentPath.RegionAndComponent regionCmp = pathItems.isEmpty() ? null : pathItems.get(0);
final Region region = regionCmp == null ? null : pageRegions.getRegion(regionCmp.getRegionName());
if (region == null) {
return pageRegions;
}
final int componentIndex = regionCmp.getComponentIndex();
final Component existingCmp = region.getComponent(componentIndex);
if (existingCmp == null) {
return pageRegions;
}
final int numberOfLevels = pathItems.size();
if (numberOfLevels == 1) {
final Region updatedRegion = Region.create(region).set(componentIndex, component).build();
return replaceRegionInPage(pageRegions, region, updatedRegion);
} else {
if (!(existingCmp instanceof LayoutComponent)) {
return pageRegions;
}
final LayoutComponent layoutComponent = (LayoutComponent) existingCmp;
final LayoutRegions layoutRegions = replaceComponentInLayout(layoutComponent.getRegions(), removeFirstLevel(pathItems), component);
final LayoutComponent updatedLayout = LayoutComponent.create(layoutComponent).regions(layoutRegions).build();
final Region updatedRegion = Region.create(region).set(componentIndex, updatedLayout).build();
return replaceRegionInPage(pageRegions, region, updatedRegion);
}
}
Aggregations