简体   繁体   中英

Liferay 7 Asset publisher new web content folder

I've two web content structures (foo and bar) in Liferay 7.0 and I want to store the web contents inside webcontents folders (webcontents/foo and webcontents/bar). I added two asset publishers, one for each structure, and I also allow the user to create new webcontents through the asset publisher plus '+' icon. However, they are created in the web content root folder (webcontents/). There is any way to dynamicaly save the webcontent that are created through the '+' icon in the asset publisher to a specific folder (based on the template itself, tags, or any other field)?

I don't think that this can be achieved without customization.

I'd create a service wrapper to determine the Folder eg by the Structure's name.

I used a "ModelListener" for this exact scenario. https://dev.liferay.com/de/develop/tutorials/-/knowledge_base/7-0/model-listeners

If you extend Liferays BaseModelListener you can use the onBeforeCreate() Method for example.
First check the ddmStructure of the current journalArticle and get or create your Folder. Now set the Folder ID for your journalArticle and your done!

Posting the code as solution suggested by @Viergelenker

public class ArticleSetListenerPortlet extends BaseModelListener<JournalArticle> {

    private static final Log LOGGER = LogFactoryUtil.getLog(ArticleSetListenerPortlet.class);

    @Override
    public void onBeforeCreate(JournalArticle model) throws ModelListenerException {
            String structureName = model.getDDMStructure().getName(Locale.US);
            long groupId = xxxxx;
            List<JournalFolder> journalFolders = JournalFolderLocalServiceUtil.getFolders(groupId);
            for(JournalFolder folder : journalFolders) {

                if("Foo".equals(folder.getName())) {
                        model.setFolderId(folder.getFolderId());
                        LOGGER.info("Set folder as Foo");
                    }

         }


            super.onBeforeCreate(model);

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM