Skip to content

Commit

Permalink
LPS-75103 Portlet 2.0: Developer-defined custom portlet modes are ign…
Browse files Browse the repository at this point in the history
…ored
  • Loading branch information
ngriffin7a authored and brianchandotcom committed Dec 5, 2017
1 parent ec68520 commit 4212a12
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
Expand Up @@ -84,6 +84,7 @@
* @author Berentey Zsolt
* @author Jorge Ferrer
* @author Raymond Augé
* @author Neil Griffin
*/
public class LayoutTypePortletImpl
extends LayoutTypeImpl implements LayoutTypePortlet {
Expand All @@ -107,6 +108,13 @@ public void addModeConfigPortletId(String portletId) {
setModeConfig(StringUtil.add(getModeConfig(), portletId));
}

public void addModeCustomPortletId(String portletId, String portletMode) {
removeModesPortletId(portletId);
setModeCustom(
StringUtil.add(getModeCustom(portletMode), portletId), portletMode);
_addedCustomPortletMode = portletMode;
}

@Override
public void addModeEditDefaultsPortletId(String portletId) {
removeModesPortletId(portletId);
Expand Down Expand Up @@ -251,6 +259,10 @@ public List<Portlet> addStaticPortlets(
return list;
}

public String getAddedCustomPortletMode() {
return _addedCustomPortletMode;
}

@Override
public List<Portlet> getAllPortlets() {
List<Portlet> explicitlyAddedPortlets = getExplicitlyAddedPortlets();
Expand Down Expand Up @@ -406,6 +418,10 @@ public String getModeConfig() {
return getTypeSettingsProperty(LayoutTypePortletConstants.MODE_CONFIG);
}

public String getModeCustom(String portletMode) {
return getTypeSettingsProperty("mode-" + portletMode);
}

@Override
public String getModeEdit() {
return getTypeSettingsProperty(LayoutTypePortletConstants.MODE_EDIT);
Expand Down Expand Up @@ -530,6 +546,12 @@ public boolean hasModeConfigPortletId(String portletId) {
return StringUtil.contains(getModeConfig(), portletId);
}

public boolean hasModeCustomPortletId(
String portletId, String portletMode) {

return StringUtil.contains(getModeCustom(portletMode), portletId);
}

@Override
public boolean hasModeEditDefaultsPortletId(String portletId) {
return StringUtil.contains(getModeEditDefaults(), portletId);
Expand Down Expand Up @@ -1204,6 +1226,10 @@ public void setModeConfig(String modeConfig) {
LayoutTypePortletConstants.MODE_CONFIG, modeConfig);
}

public void setModeCustom(String modeCustom, String portletMode) {
setTypeSettingsProperty("mode-" + portletMode, modeCustom);
}

@Override
public void setModeEdit(String modeEdit) {
setTypeSettingsProperty(LayoutTypePortletConstants.MODE_EDIT, modeEdit);
Expand Down Expand Up @@ -2013,6 +2039,7 @@ private void _removeNestedColumns(

private static final Layout _nullLayout = new LayoutImpl();

private String _addedCustomPortletMode;
private boolean _customizedView;
private final Format _dateFormat =
FastDateFormatFactoryUtil.getSimpleDateFormat(
Expand Down
19 changes: 17 additions & 2 deletions portal-impl/src/com/liferay/portal/util/PortalImpl.java
Expand Up @@ -201,6 +201,7 @@
import com.liferay.portal.language.LanguageResources;
import com.liferay.portal.model.impl.CookieRemotePreference;
import com.liferay.portal.model.impl.LayoutTypeImpl;
import com.liferay.portal.model.impl.LayoutTypePortletImpl;
import com.liferay.portal.plugin.PluginPackageUtil;
import com.liferay.portal.security.jaas.JAASHelper;
import com.liferay.portal.security.lang.DoPrivilegedUtil;
Expand Down Expand Up @@ -312,6 +313,7 @@
* @author Hugo Huijser
* @author Juan Fernández
* @author Marco Leo
* @author Neil Griffin
*/
@DoPrivileged
public class PortalImpl implements Portal {
Expand Down Expand Up @@ -553,7 +555,7 @@ public PortalImpl() {
portalInetSocketAddressEventListenerServiceTracker =
registry.trackServices(
PortalInetSocketAddressEventListener.class,
new PortalInetSocketAddressEventListenerServiceTrackerCustomizer());
new PortalInetSocketAddressEventListenerSTC());

portalInetSocketAddressEventListenerServiceTracker.open();
}
Expand Down Expand Up @@ -7170,6 +7172,19 @@ else if (portletMode.equals(PortletMode.VIEW) &&

updateLayout = true;
}
else if (layoutType instanceof LayoutTypePortletImpl) {
LayoutTypePortletImpl layoutTypePortletImpl =
(LayoutTypePortletImpl)layoutType;

if (!layoutTypePortletImpl.hasModeCustomPortletId(
portletId, portletMode.toString())) {

layoutTypePortletImpl.addModeCustomPortletId(
portletId, portletMode.toString());

updateLayout = true;
}
}

if (updateLayout &&
PortletPermissionUtil.contains(
Expand Down Expand Up @@ -8868,7 +8883,7 @@ public void removedService(

}

private class PortalInetSocketAddressEventListenerServiceTrackerCustomizer
private class PortalInetSocketAddressEventListenerSTC
implements ServiceTrackerCustomizer
<PortalInetSocketAddressEventListener,
PortalInetSocketAddressEventListener> {
Expand Down
9 changes: 9 additions & 0 deletions portal-web/docroot/html/portal/render_portlet.jsp
Expand Up @@ -122,6 +122,15 @@ else if (modePreview) {
else if (modePrint) {
portletMode = LiferayPortletMode.PRINT;
}
else if (layoutTypePortlet instanceof LayoutTypePortletImpl) {
LayoutTypePortletImpl layoutTypePortletImpl = (LayoutTypePortletImpl)layoutTypePortlet;
String customPortletMode = layoutTypePortletImpl.getAddedCustomPortletMode();
if (customPortletMode != null) {
portletMode = new PortletMode(customPortletMode);
}
}
InvokerPortlet invokerPortlet = null;
Expand Down

0 comments on commit 4212a12

Please sign in to comment.