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)?
Asked
Active
Viewed 622 times
3 Answers
1
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.

Tamás Molnár
- 11
- 1
-
It would be nice to explain a bit and add some relevant code, if the link becomes unavailable. – Praveen Kumar Purushothaman Jan 21 '19 at 13:10
-
the link is the official documentation. the answer can be without code, saying "you need to perform a customization". In LR 6.2 it would be called Hook, in 7.0 we have a service wrapper. Is an overwrite of LR default behavior. I will keep this question open in order to see any other opinion regarding configurations. – X-Pippes Jan 21 '19 at 13:49
1
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!

Viergelenker
- 336
- 1
- 8
0
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);
}

X-Pippes
- 1,170
- 7
- 25
-
1Thanks for your addition! Just one minor improvement to hopefully reduce runtime: `JournalFolder folder = JournalFolderLocalServiceUtil.fetchFolder( groupId, title );` Not sure about the implementation, but this should do a database query and you won't need a for-loop :) – Viergelenker Jan 31 '19 at 14:19
-
I understand. But in my case, I do have several folders so I need the for :) – X-Pippes Jan 31 '19 at 18:03