Search in sources :

Example 16 with Region

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

the class ComponentInstructionTest method createPage.

private Content createPage(final String id, final String name, final String contentTypeName) {
    PropertyTree rootDataSet = new PropertyTree();
    rootDataSet.addString("property1", "value1");
    Region region = Region.create().name("myRegion").add(PartComponent.create().descriptor(DescriptorKey.from("myapplication:myparttemplate")).build()).build();
    PageRegions pageRegions = PageRegions.create().add(region).build();
    Page page = Page.create().template(PageTemplateKey.from("my-page")).regions(pageRegions).build();
    return Content.create().id(ContentId.from(id)).path(ContentPath.from(name)).owner(PrincipalKey.from("user:myStore:me")).displayName("My Content").modifier(PrincipalKey.from("user:system:admin")).type(ContentTypeName.from(contentTypeName)).page(page).build();
}
Also used : PageRegions(com.enonic.xp.page.PageRegions) PropertyTree(com.enonic.xp.data.PropertyTree) Region(com.enonic.xp.region.Region) Page(com.enonic.xp.page.Page)

Example 17 with Region

use of com.enonic.xp.region.Region 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);
    }
}
Also used : ComponentPath(com.enonic.xp.region.ComponentPath) Region(com.enonic.xp.region.Region) 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

Region (com.enonic.xp.region.Region)17 PropertyTree (com.enonic.xp.data.PropertyTree)8 Component (com.enonic.xp.region.Component)4 LayoutComponent (com.enonic.xp.region.LayoutComponent)4 DescriptorKey (com.enonic.xp.page.DescriptorKey)3 Page (com.enonic.xp.page.Page)3 PageRegions (com.enonic.xp.page.PageRegions)3 ComponentPath (com.enonic.xp.region.ComponentPath)3 LayoutRegions (com.enonic.xp.region.LayoutRegions)3 PartComponent (com.enonic.xp.region.PartComponent)3 Test (org.junit.jupiter.api.Test)3 Form (com.enonic.xp.form.Form)2 LayoutDescriptor (com.enonic.xp.region.LayoutDescriptor)2 AbstractEqualsTest (com.enonic.xp.support.AbstractEqualsTest)2 AbstractDataSerializerTest (com.enonic.xp.core.impl.content.page.AbstractDataSerializerTest)1 PropertySet (com.enonic.xp.data.PropertySet)1 FormDefaultValuesProcessor (com.enonic.xp.form.FormDefaultValuesProcessor)1 PageDescriptor (com.enonic.xp.page.PageDescriptor)1 PageDescriptorService (com.enonic.xp.page.PageDescriptorService)1 DescriptorBasedComponent (com.enonic.xp.region.DescriptorBasedComponent)1