-
Notifications
You must be signed in to change notification settings - Fork 81
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
CIF-2188 - Expose HTML id attribute in component edit dialogs #639
Changes from 2 commits
5144ae1
2e93482
d78d820
2cad8b9
9788641
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,23 +15,28 @@ | |
|
||
import javax.inject.Inject; | ||
|
||
import org.apache.commons.codec.digest.DigestUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.sling.api.resource.Resource; | ||
import org.apache.sling.api.resource.ValueMap; | ||
import org.apache.sling.caconfig.ConfigurationBuilder; | ||
import org.apache.sling.models.annotations.injectorspecific.Self; | ||
|
||
import com.adobe.cq.commerce.core.components.datalayer.CategoryData; | ||
import com.adobe.cq.wcm.core.components.models.Component; | ||
import com.adobe.cq.wcm.core.components.models.datalayer.AssetData; | ||
import com.adobe.cq.wcm.core.components.models.datalayer.ComponentData; | ||
import com.adobe.cq.wcm.core.components.util.ComponentUtils; | ||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
|
||
public abstract class DataLayerComponent { | ||
public static final String ID_SEPARATOR = "-"; | ||
public static final String ID_SEPARATOR = ComponentUtils.ID_SEPARATOR; | ||
|
||
@Inject | ||
protected Resource resource; | ||
|
||
@Self | ||
private Component wcmComponent; | ||
|
||
private String id; | ||
private Boolean dataLayerEnabled; | ||
private ComponentData componentData; | ||
|
@@ -67,10 +72,14 @@ protected ComponentData getComponentData() { | |
} | ||
|
||
protected String generateId() { | ||
String resourceType = resource.getResourceType(); | ||
String prefix = StringUtils.substringAfterLast(resourceType, "/"); | ||
String path = resource.getPath(); | ||
return StringUtils.join(prefix, ID_SEPARATOR, StringUtils.substring(DigestUtils.sha256Hex(path), 0, 10)); | ||
if (wcmComponent == null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how can We only have 2 models using an optional default injection strategy (button v1 and v2). For all others the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DataLayerComponent is also extended by classes which are not Sling models, we handle that case here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add this detail to the javadoc of the class while you are on it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What detail? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That this abstract class may be extended by classes that are annotated as sling models and others that are not. |
||
String resourceType = resource.getResourceType(); | ||
String prefix = StringUtils.substringAfterLast(resourceType, "/"); | ||
String path = resource.getPath(); | ||
return ComponentUtils.generateId(prefix, path); | ||
} else { | ||
return wcmComponent.getId(); | ||
} | ||
} | ||
|
||
public String getId() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"product-8309e8957e": { | ||
"product-a8f26bcdca": { | ||
"xdm:SKU": "MJ01", | ||
"xdm:listPrice": 58.0, | ||
"xdm:categories": [ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"product-500741b9f1": { | ||
"product-4489fda6a6": { | ||
"xdm:SKU": "MH01", | ||
"xdm:listPrice": 52.0, | ||
"xdm:assets": [ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" | ||
jcr:primaryType="nt:unstructured" | ||
jcr:title="Search Bar" | ||
sling:resourceType="cq/gui/components/authoring/dialog" | ||
trackingFeature="cif-core-components:searchbar:v1"> | ||
<content | ||
jcr:primaryType="nt:unstructured" | ||
sling:resourceType="granite/ui/components/coral/foundation/container"> | ||
<items jcr:primaryType="nt:unstructured"> | ||
<column jcr:primaryType="nt:unstructured" | ||
sling:resourceType="granite/ui/components/coral/foundation/container"> | ||
<items jcr:primaryType="nt:unstructured"> | ||
<id jcr:primaryType="nt:unstructured" | ||
sling:resourceType="granite/ui/components/coral/foundation/form/textfield" | ||
fieldDescription="HTML ID attribute to apply to the component." | ||
fieldLabel="ID" | ||
name="./id"/> | ||
</items> | ||
</column> | ||
</items> | ||
</content> | ||
</jcr:root> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why redefining the const instead of using
ComponentUtils.ID_SEPARATOR
directly via static import?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ID_SEPARATOR is used at more other places in the codebe in sub-classes of DataLayerComponnet. If you define it here you don't need any static import in many other files. In fact the constant was defined earlier, I've just aligned the definition with ComponentUtils.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know the constant was defined earlier and it was wrong. So instead of having the same constant twice I would prefer to remove it and only use
ComponentUtils.ID_SEPARATOR
. The static import should not hurt.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 - this is more explicit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've inlined the ID_SEPARATOR constant.