Skip to content

Commit 43baa18

Browse files
Muskan Guptaci-build
authored andcommitted
Clientlib changes
1 parent 60ae7f0 commit 43baa18

File tree

4 files changed

+73
-3
lines changed

4 files changed

+73
-3
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.adobe.cq.forms.core.components.internal.constants;
2+
3+
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4+
~ Copyright 2024 Adobe
5+
~
6+
~ Licensed under the Apache License, Version 2.0 (the "License");
7+
~ you may not use this file except in compliance with the License.
8+
~ You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
18+
19+
public class ThemeConstants {
20+
21+
public static final String RELATIVE_PATH_METADATA = "/metadata";
22+
public static final String THEME_OVERRIDE = "themeOverride";
23+
public static final String THEME_REF = "themeRef";
24+
public static final String PROPERTY_CLIENTLIB_CATEGORY = "clientlibCategory";
25+
26+
}

bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/form/FormStructureParserImpl.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
import java.io.StringWriter;
1919
import java.io.Writer;
2020

21+
import org.apache.commons.lang3.StringUtils;
2122
import org.apache.sling.api.SlingHttpServletRequest;
2223
import org.apache.sling.api.resource.Resource;
24+
import org.apache.sling.api.resource.ValueMap;
2325
import org.apache.sling.models.annotations.Model;
2426
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
2527
import org.apache.sling.models.annotations.injectorspecific.SlingObject;
@@ -28,6 +30,8 @@
2830
import org.slf4j.Logger;
2931
import org.slf4j.LoggerFactory;
3032

33+
import com.adobe.aemds.guide.service.GuideException;
34+
import com.adobe.cq.forms.core.components.internal.constants.ThemeConstants;
3135
import com.adobe.cq.forms.core.components.models.form.FormContainer;
3236
import com.adobe.cq.forms.core.components.models.form.FormStructureParser;
3337
import com.adobe.cq.forms.core.components.models.form.HtlUtil;
@@ -60,6 +64,36 @@ public String getClientLibRefFromFormContainer() {
6064
return getPropertyFromFormContainer(resource, FormContainer.PN_CLIENT_LIB_REF);
6165
}
6266

67+
@Override
68+
public String getThemeClientLibRefFromFormContainer() {
69+
String themeContentPath = null;
70+
String themeClientLibRef = null;
71+
if (request != null) {
72+
themeContentPath = (String) request.getAttribute(ThemeConstants.THEME_OVERRIDE); // theme editor use-case
73+
}
74+
if (StringUtils.isBlank(themeContentPath)) {
75+
if (request != null) {
76+
themeContentPath = request.getParameter(ThemeConstants.THEME_OVERRIDE); // embed component use-case
77+
}
78+
if (StringUtils.isBlank(themeContentPath)) {
79+
themeContentPath = getPropertyFromFormContainer(resource, ThemeConstants.THEME_REF); // normal including theme in form
80+
// runtime
81+
}
82+
}
83+
// get client library from theme content path
84+
if (StringUtils.isNotBlank(themeContentPath)) {
85+
Resource themeResource = resource.getResourceResolver().getResource(themeContentPath + ThemeConstants.RELATIVE_PATH_METADATA);
86+
if (themeResource != null) {
87+
ValueMap themeProps = themeResource.getValueMap();
88+
themeClientLibRef = themeProps.get(ThemeConstants.PROPERTY_CLIENTLIB_CATEGORY, "");
89+
} else {
90+
throw new GuideException("Invalid Theme Name " + themeContentPath);
91+
}
92+
}
93+
94+
return themeClientLibRef;
95+
}
96+
6397
@Override
6498
public Boolean containsFormContainer() {
6599
return containsFormContainer(resource);

bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/FormStructureParser.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ public interface FormStructureParser {
3737
*/
3838
String getClientLibRefFromFormContainer();
3939

40+
/**
41+
*
42+
* @returns reference to the client lib of the theme from form container
43+
*/
44+
String getThemeClientLibRefFromFormContainer();
45+
4046
/**
4147
* Checks if this resource contains a form container
4248
*

ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/page/v1/page/customheaderlibs.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@
1414
~ limitations under the License.
1515
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/-->
1616
<sly data-sly-use.clientlib="core/wcm/components/commons/v1/templates/clientlib.html"
17-
data-sly-use.formstructparser="com.adobe.cq.forms.core.components.models.form.FormStructureParser"
18-
data-sly-test.clientLibRef="${formstructparser.clientLibRefFromFormContainer}">
19-
<sly data-sly-test="${clientLibRef}" data-sly-call="${clientlib.css @ categories=clientLibRef}"/>
17+
data-sly-use.formstructparser="com.adobe.cq.forms.core.components.models.form.FormStructureParser">
18+
<sly data-sly-test.clientLibRef="${formstructparser.clientLibRefFromFormContainer}">
19+
<sly data-sly-call="${clientlib.css @ categories=clientLibRef}"/>
20+
</sly>
21+
<sly data-sly-test.clientLibRefTheme="${formstructparser.themeClientLibRefFromFormContainer}">
22+
<sly data-sly-call="${clientlib.css @ categories=clientLibRefTheme}"/>
23+
</sly>
2024
</sly>
2125
<sly data-sly-use.clientlib="core/wcm/components/commons/v1/templates/clientlib.html">
2226
<!-- Loading runtime css in authoring -->

0 commit comments

Comments
 (0)