1
votes

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)?

3

3 Answers

1
votes

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!

1
votes

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

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

0
votes

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);

    }