Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Wanted to add site programmatically in asset publisher scope.
Hello Everyone,
Actually i have task such that after creating site that site should be added directly to the asset publisher scope feature. Can i acheive this? If yes, please let me know how can i achieve this? and no, than please provide reason for it.
Thanks and regards.
Happy Learining!!
Tricky. Do you need this for a specific page/asset publisher?
In any case: You probably would need to add a listener for groups to notice when a site is added.
https://help.liferay.com/hc/en-us/articles/360018170891-Model-Listener
And then you would need to read the configuration for the relevant asset publishers and add the id of the group to the xml. But this is quite difficult since you won't find a lot of sample code for something like that.
I wanted to do achieve this for page where my asset publisher is there.Do you have any sample code?
Thanks & regards.
Well, I can only guess what has to be done. I think, you have to iterate through all pages.
List<Layout> pageLayouts = layoutLocalService.getLayouts(-1,-1);
// That's probably too many, you probably want to fetch only layouts of a particular site
for(Layout pageLayout : pageLayouts {
// Now, you need to find the portlets on these pages
LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet)
pageLayout.getLayoutType();
List<String> portletIds =
layoutTypePortlet.getPortletIds();
for (String portletId :
portletIds) {
// Now, we need the portlet preferences for each of these
portlets
PortletPreferencesIds portletPreferencesIds =
PortletPreferencesFactoryUtil.getPortletPreferencesIds(pageLayout.getGroupId(),
pageLayout.getUserId(), pageLayout, portletId);
PortletPreferences portletPreferences =
portletPreferencesLocalService.getPreferences(portletPreferencesIds);
String values = portletPreferences.getPreferences();
// Check what's in there, then update it
}
I would try that on one page, to check if it even contains the relevant information. I could be totally off here, I just pieced it together from the API.