Message Boards

Wanted to add site programmatically in asset publisher scope.

Sanat D, modified 3 Years ago.

Wanted to add site programmatically in asset publisher scope.

New Member Posts: 17 Join Date: 9/8/20 Recent Posts

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!!

thumbnail
Christoph Rabel, modified 3 Years ago.

RE: Wanted to add site programmatically in asset publisher scope.

Liferay Legend Posts: 1554 Join Date: 9/24/09 Recent Posts

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.

Sanat D, modified 3 Years ago.

RE: RE: Wanted to add site programmatically in asset publisher scope.

New Member Posts: 17 Join Date: 9/8/20 Recent Posts

I wanted to do achieve this for page where my asset publisher is there.Do you have any sample code?

Thanks & regards.

thumbnail
Christoph Rabel, modified 3 Years ago.

RE: Wanted to add site programmatically in asset publisher scope.

Liferay Legend Posts: 1554 Join Date: 9/24/09 Recent Posts

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.