Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LPS-60024 insert classes into the themes from the modules (not hardcoding init.ftl) #34615

Closed
wants to merge 8 commits into from
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/

package com.liferay.control.menu.theme;

import com.liferay.portal.kernel.template.TemplateContextContributor;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.model.User;
import com.liferay.portal.theme.ThemeDisplay;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.osgi.service.component.annotations.Component;

/**
*
* @author Julio Camarero
*/

@Component(
immediate = true,
property = {"type=" + TemplateContextContributor.TYPE_THEME},
service = TemplateContextContributor.class
)

public class ControlMenuTemplateContextContributor
implements TemplateContextContributor {

@Override
public void prepare(
Map<String, Object> contextObjects, HttpServletRequest request) {

if (!isShowControlMenu(request)) {
return;
}

String cssClass = GetterUtil.getString(
contextObjects.get("bodyCssClass"));

contextObjects.put("bodyCssClass", cssClass + " has-control-menu");
}

protected boolean isShowControlMenu(HttpServletRequest request) {
ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
WebKeys.THEME_DISPLAY);

if (!themeDisplay.isSignedIn()) {
return false;
}

User user = themeDisplay.getUser();

if (!user.isSetupComplete()) {
return false;
}

return true;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/

package com.liferay.product.navigation.product.menu.web.theme;

import com.liferay.portal.kernel.template.TemplateContextContributor;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.model.User;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.portal.util.SessionClicks;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.osgi.service.component.annotations.Component;

/**
*
* @author Julio Camarero
*/

@Component(
immediate = true,
property = {"type=" + TemplateContextContributor.TYPE_THEME},
service = TemplateContextContributor.class
)

public class ProductMenuTemplateContextContributor
implements TemplateContextContributor {

@Override
public void prepare(
Map<String, Object> contextObjects, HttpServletRequest request) {

if (!isShowProductMenu(request)) {
return;
}

String productMenuState = SessionClicks.get(
request, "com.liferay.control.menu.web_productMenuState", "closed");

contextObjects.put("liferay_product_menu_state", productMenuState);

String cssClass = GetterUtil.getString(
contextObjects.get("bodyCssClass"));

contextObjects.put(
"bodyCssClass", cssClass + StringPool.SPACE + productMenuState);
}

protected boolean isShowProductMenu(HttpServletRequest request) {
ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
WebKeys.THEME_DISPLAY);

if (!themeDisplay.isSignedIn()) {
return false;
}

User user = themeDisplay.getUser();

if (!user.isSetupComplete()) {
return false;
}

return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ${theme.include(body_top_include)}

<#assign scope_group = theme_display.getScopeGroup()>

<@liferay.product_menu_sidebar state="${liferay_product_menu_state}" />
<@liferay.product_menu_sidebar state="${liferay_product_menu_state!}" />

<div id="wrapper">
<div id="content-wrapper">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

${theme.include(body_top_include)}

<@liferay.product_menu_sidebar state="${liferay_product_menu_state}" />
<@liferay.product_menu_sidebar state="${liferay_product_menu_state!}" />

<#if is_setup_complete && is_signed_in>
<@liferay_control_menu["control-menu"] />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
<#assign theme_settings = themeDisplay.getThemeSettings() />

<#assign root_css_class = languageUtil.get(locale, "lang.dir") />
<#assign css_class = htmlUtil.escape(theme_display.getColorScheme().getCssClass()) + " yui3-skin-sam" />
<#assign css_class = htmlUtil.escape(bodyCssClass!) />

<#assign liferay_product_menu_state = sessionClicks.get(request, "com.liferay.control.menu.web_productMenuState", "closed") />

<#assign css_class = css_class + " " + liferay_product_menu_state />
<#assign css_class = css_class + " " + htmlUtil.escape(theme_display.getColorScheme().getCssClass()) + " yui3-skin-sam" />

<#assign liferay_toggle_controls = sessionClicks.get(request, "com.liferay.frontend.js.web_toggleControls", "visible") />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
#set ($theme_settings = $themeDisplay.getThemeSettings())

#set ($root_css_class = $languageUtil.get($locale, "lang.dir"))
#set ($css_class = $htmlUtil.escape($theme_display.getColorScheme().getCssClass()) + " yui3-skin-sam")
#set ($css_class = $htmlUtil.escape($!bodyCssClass))

#set ($liferay_product_menu_state = $sessionClicks.get($request, "com.liferay.control.menu.web_productMenuState", "closed"))

#set ($css_class = $css_class + " " + $liferay_product_menu_state)
#set ($css_class = $css_class + " " + $htmlUtil.escape($theme_display.getColorScheme().getCssClass()) + " yui3-skin-sam")

#set ($liferay_toggle_controls = $sessionClicks.get($request, "com.liferay.frontend.js.web_toggleControls", "visible"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

${theme.include(body_top_include)}

<@liferay.product_menu_sidebar state="${liferay_product_menu_state}" />
<@liferay.product_menu_sidebar state="${liferay_product_menu_state!}" />

<@liferay.control_menu />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

$theme.include($body_top_include)

#product_menu_sidebar($liferay_product_menu_state)
#product_menu_sidebar($!liferay_product_menu_state)

#control_menu()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ protected void populateExtraHelperUtilities(
cardinality = ReferenceCardinality.MULTIPLE,
policy = ReferencePolicy.DYNAMIC,
policyOption = ReferencePolicyOption.GREEDY,
target = "(type=" + TemplateContextContributor.TYPE_GLOBAL + ")",
unbind = "unregisterTemplateContextContributor"
)
protected synchronized void registerTemplateContextContributor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ protected void populateExtraHelperUtilities(
cardinality = ReferenceCardinality.MULTIPLE,
policy = ReferencePolicy.DYNAMIC,
policyOption = ReferencePolicyOption.GREEDY,
target = "(type=" + TemplateContextContributor.TYPE_GLOBAL + ")",
unbind = "unregisterTemplateContextContributor"
)
protected synchronized void registerTemplateContextContributor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<@liferay_control_menu["control-menu"] />
</#if>

<@liferay.product_menu_sidebar state="${liferay_product_menu_state}" />
<@liferay.product_menu_sidebar state="${liferay_product_menu_state!}" />

<div id="wrapper">
<header id="banner" role="banner">
Expand Down
2 changes: 1 addition & 1 deletion modules/themes/user-theme/src/templates/portal_normal.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

${theme.include(body_top_include)}

<@liferay.product_menu_sidebar state="${liferay_product_menu_state}" />
<@liferay.product_menu_sidebar state="${liferay_product_menu_state!}" />

<#if is_setup_complete && is_signed_in>
<@liferay_control_menu["control-menu"] />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ public String toString() {
contextObjects.put("colorScheme", themeDisplay.getColorScheme());
contextObjects.put(
"portletDisplay", themeDisplay.getPortletDisplay());
contextObjects.put("bodyCssClass", StringPool.BLANK);

// Navigation items

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
*/
public interface TemplateContextContributor {

public static final String TYPE_GLOBAL = "GLOBAL";

public static final String TYPE_THEME = "THEME";

public void prepare(
Map<String, Object> contextObjects, HttpServletRequest request);

Expand Down
24 changes: 24 additions & 0 deletions util-taglib/src/com/liferay/taglib/util/ThemeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.liferay.portal.kernel.servlet.taglib.DynamicIncludeUtil;
import com.liferay.portal.kernel.template.Template;
import com.liferay.portal.kernel.template.TemplateConstants;
import com.liferay.portal.kernel.template.TemplateContextContributor;
import com.liferay.portal.kernel.template.TemplateManager;
import com.liferay.portal.kernel.template.TemplateManagerUtil;
import com.liferay.portal.kernel.template.TemplateResource;
Expand All @@ -35,6 +36,8 @@
import com.liferay.portal.model.Theme;
import com.liferay.portal.theme.PortletDisplay;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.registry.collections.ServiceTrackerCollections;
import com.liferay.registry.collections.ServiceTrackerList;
import com.liferay.taglib.servlet.PipingServletResponse;

import java.io.Writer;
Expand Down Expand Up @@ -239,6 +242,14 @@ protected static String doIncludeFTL(

template.prepare(request);

// Custom theme variables

for (TemplateContextContributor templateContextContributor :
_templateContextContributors) {

templateContextContributor.prepare(template, request);
}

// Theme servlet context

ServletContext themeServletContext = ServletContextPool.get(
Expand Down Expand Up @@ -416,6 +427,14 @@ protected static String doIncludeVM(

template.prepare(request);

// Custom theme variables

for (TemplateContextContributor templateContextContributor :
_templateContextContributors) {

templateContextContributor.prepare(template, request);
}

// Theme servlet context

ServletContext themeServletContext = ServletContextPool.get(
Expand Down Expand Up @@ -454,4 +473,9 @@ protected static String doIncludeVM(

private static final Log _log = LogFactoryUtil.getLog(ThemeUtil.class);

private static final ServiceTrackerList<TemplateContextContributor>
_templateContextContributors = ServiceTrackerCollections.openList(
TemplateContextContributor.class,
"(type=" + TemplateContextContributor.TYPE_THEME + ")");

}