Search in sources :

Example 1 with PageTemplates

use of com.enonic.xp.page.PageTemplates in project xp by enonic.

the class GetPageTemplateBySiteCommand method execute.

public PageTemplates execute() {
    final PageTemplates.Builder pageTemplatesBuilder = PageTemplates.create();
    if (sitePath == null) {
        final Content site = contentService.getById(siteId);
        sitePath = site.getPath();
    }
    final ContentPath pageTemplatesFolderPath = ContentPath.from(sitePath, ContentServiceImpl.TEMPLATES_FOLDER_NAME);
    final FindContentByParentParams.Builder findContentByParentParams = FindContentByParentParams.create().parentPath(pageTemplatesFolderPath);
    if (supportedContentTypes != null) {
        final ValueFilter.Builder supportsContentTypeFilter = ValueFilter.create().fieldName("data.supports");
        supportedContentTypes.forEach(supportedContentType -> {
            supportsContentTypeFilter.addValue(ValueFactory.newString(supportedContentType.toString()));
        });
        findContentByParentParams.queryFilter(supportsContentTypeFilter.build());
    }
    if (size != null) {
        findContentByParentParams.size(size);
    }
    final FindContentByParentResult result = contentService.findByParent(findContentByParentParams.build());
    for (final Content content : result.getContents()) {
        if (content instanceof PageTemplate) {
            pageTemplatesBuilder.add((PageTemplate) content);
        }
    }
    return pageTemplatesBuilder.build();
}
Also used : FindContentByParentParams(com.enonic.xp.content.FindContentByParentParams) FindContentByParentResult(com.enonic.xp.content.FindContentByParentResult) PageTemplate(com.enonic.xp.page.PageTemplate) Content(com.enonic.xp.content.Content) PageTemplates(com.enonic.xp.page.PageTemplates) ValueFilter(com.enonic.xp.query.filter.ValueFilter) ContentPath(com.enonic.xp.content.ContentPath)

Aggregations

Content (com.enonic.xp.content.Content)1 ContentPath (com.enonic.xp.content.ContentPath)1 FindContentByParentParams (com.enonic.xp.content.FindContentByParentParams)1 FindContentByParentResult (com.enonic.xp.content.FindContentByParentResult)1 PageTemplate (com.enonic.xp.page.PageTemplate)1 PageTemplates (com.enonic.xp.page.PageTemplates)1 ValueFilter (com.enonic.xp.query.filter.ValueFilter)1