Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions dotCMS/src/main/java/com/dotcms/graphql/ContentFields.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import static com.dotmarketing.portlets.contentlet.model.Contentlet.PUBLISH_DATE_KEY;
import static com.dotmarketing.portlets.contentlet.model.Contentlet.PUBLISH_USER_KEY;
import static com.dotmarketing.portlets.contentlet.model.Contentlet.TITLE_IMAGE_KEY;
import static com.dotmarketing.portlets.contentlet.model.Contentlet.STYLE_PROPERTIES_KEY;
import static graphql.Scalars.GraphQLBoolean;
import static graphql.Scalars.GraphQLID;
import static graphql.Scalars.GraphQLInt;
Expand Down Expand Up @@ -97,6 +98,13 @@ public static Map<String, TypeFetcher> getContentFields() {
: "")));
contentFields.put(PUBLISH_USER_KEY, new TypeFetcher(GraphQLTypeReference.typeRef(USER.getTypeName()),
new UserDataFetcher()));

contentFields.put(STYLE_PROPERTIES_KEY, new TypeFetcher(ExtendedScalars.Json, PropertyDataFetcher
.fetching((Function<Contentlet, Object>) contentlet ->
UtilMethods.isSet(contentlet.get(STYLE_PROPERTIES_KEY))
? contentlet.get(STYLE_PROPERTIES_KEY)
: null)));

return contentFields;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,14 +537,18 @@ private void widgetPreExecute(final Contentlet contentlet) {
* properties from the MultiTree relationship
*/
private void addStyles(Contentlet contentlet, PersonalizedContentlet personalizedContentlet) {
// NOTE: Safe to modify contentlet.getMap() here because the contentlet is a COPY
// created by hydrate(), not the cached original instance.
// See: DotContentletTransformerImpl.hydrate() and copy()

if (!Config.getBooleanProperty("FEATURE_FLAG_UVE_STYLE_EDITOR", false)) {
return;
}

final Map<String, Object> styleProperties = personalizedContentlet.getStyleProperties();

if (UtilMethods.isSet(styleProperties) && !styleProperties.isEmpty()) {
contentlet.getMap().put("styleProperties", styleProperties);
contentlet.getMap().put(Contentlet.STYLE_PROPERTIES_KEY, styleProperties);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public class Contentlet implements Serializable, Permissionable, Categorizable,
public static final String DONT_VALIDATE_ME = "_dont_validate_me";
public static final String DISABLE_WORKFLOW = "__disable_workflow__";
public static final String VALIDATE_EMPTY_FILE = "_validateEmptyFile_";
public static final String STYLE_PROPERTIES_KEY = "styleProperties";

// means the contentlet is being used on unit test mode.
// this is only for unit test. do not use on production.
Expand Down
41 changes: 19 additions & 22 deletions dotcms-postman/src/main/resources/postman/GraphQLTests.json
Original file line number Diff line number Diff line change
Expand Up @@ -4660,12 +4660,7 @@
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"pm.test(\"FEATURE_FLAG_UVE_STYLE_EDITOR is enabled\", function () {",
" const entity = pm.response.json().entity;",
" pm.expect(entity).to.exist;",
" pm.expect(entity).to.eql('FEATURE_FLAG_UVE_STYLE_EDITOR saved/updated');",
"});"
""
],
"type": "text/javascript",
"packages": {},
Expand All @@ -4686,7 +4681,7 @@
}
},
"url": {
"raw": "{{serverURL}}/api/v1/system-table/",
"raw": "{{serverURL}}/api/v1/system-table",
"host": [
"{{serverURL}}"
],
Expand Down Expand Up @@ -4724,13 +4719,13 @@
" pm.expect(response.data.page).to.exist;",
"});",
"",
"// Finding the Container (Logic adjusted for nested structure)",
"// Finding the Container",
"let targetContainerWrapper = null;",
"",
"pm.test(\"Target Container exists\", function () {",
" const containers = response.data.page.containers;",
" ",
" // We have to look inside the 'containerContentlets' array of each container to find the UUID 'uuid-1'",
" // Look inside the 'containerContentlets' array to find the UUID 'uuid-1'",
" containers.forEach(container => {",
" if(container.containerContentlets) {",
" const found = container.containerContentlets.find(c => c.uuid === 'uuid-1');",
Expand All @@ -4752,14 +4747,21 @@
" pm.expect(targetContentlet, \"Contentlet not found\").to.exist;",
"});",
"",
"// Checking Style Values",
"pm.test(\"Styles have correct width\", function () {",
"// Checking Style Values inside _map Object",
"pm.test(\"_map Styles have correct width\", function () {",
" pm.expect(targetContentlet.styles).to.not.be.null;",
" pm.expect(targetContentlet.styles.width).to.eql('100px');",
" pm.expect(targetContentlet.styles.color).to.eql('#FF0000');",
" pm.expect(targetContentlet.styles.margin).to.eql('10px');",
"});",
""
"",
"// Checking Style Values as a top level field",
"pm.test(\"Top level Styles have correct width\", function () {",
" pm.expect(targetContentlet.styleProperties).to.not.be.null;",
" pm.expect(targetContentlet.styleProperties.width).to.eql('100px');",
" pm.expect(targetContentlet.styleProperties.color).to.eql('#FF0000');",
" pm.expect(targetContentlet.styleProperties.margin).to.eql('10px');",
"});"
],
"type": "text/javascript",
"packages": {},
Expand All @@ -4778,7 +4780,7 @@
"body": {
"mode": "graphql",
"graphql": {
"query": "query getPageData($url: String!) {\n page(url: $url) {\n containers {\n containerContentlets {\n uuid\n contentlets {\n identifier\n title\n styles: _map(key: \"styleProperties\")\n }\n }\n }\n }\n}\n",
"query": "query getPageData($url: String!) {\n page(url: $url) {\n containers {\n containerContentlets {\n uuid\n contentlets {\n identifier\n title\n styles: _map(key: \"styleProperties\")\n styleProperties\n }\n }\n }\n }\n}\n",
"variables": "{\n \"url\": \"{{pageUrl}}\"\n}"
}
},
Expand Down Expand Up @@ -4806,12 +4808,7 @@
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"pm.test(\"FEATURE_FLAG_UVE_STYLE_EDITOR is disabled\", function () {",
" const entity = pm.response.json().entity;",
" pm.expect(entity).to.exist;",
" pm.expect(entity).to.eql('FEATURE_FLAG_UVE_STYLE_EDITOR Deleted');",
"});"
""
],
"type": "text/javascript",
"packages": {},
Expand All @@ -4824,23 +4821,23 @@
"header": [],
"body": {
"mode": "raw",
"raw": "{\"key\":\"FEATURE_FLAG_UVE_STYLE_EDITOR\"}",
"raw": "",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{serverURL}}/api/v1/system-table/_delete",
"raw": "{{serverURL}}/api/v1/system-table/FEATURE_FLAG_UVE_STYLE_EDITOR",
"host": [
"{{serverURL}}"
],
"path": [
"api",
"v1",
"system-table",
"_delete"
"FEATURE_FLAG_UVE_STYLE_EDITOR"
]
}
},
Expand Down