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

GarageWeek2021 - composable components #1906

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -45,6 +45,7 @@
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageManager;
import com.day.cq.wcm.api.designer.Style;
import com.day.cq.wcm.commons.WCMUtils;
import com.fasterxml.jackson.annotation.JsonIgnore;

@Model(adaptables = SlingHttpServletRequest.class,
Expand Down Expand Up @@ -100,6 +101,7 @@ private void initModel() {

if (heading == null) {
heading = Heading.getHeading(type);
Style currentStyle = WCMUtils.getStyle(request);
if (heading == null && currentStyle != null) {
heading = Heading.getHeading(currentStyle.get(PN_DESIGN_DEFAULT_TYPE, String.class));
}
Expand Down
Expand Up @@ -17,18 +17,22 @@

import java.util.Optional;

import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Exporter;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.ScriptVariable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.adobe.cq.export.json.ComponentExporter;
import com.adobe.cq.export.json.ExporterConstants;
import com.adobe.cq.wcm.core.components.commons.link.Link;
import com.adobe.cq.wcm.core.components.internal.Utils;
import com.adobe.cq.wcm.core.components.internal.resource.CoreResourceWrapper;
import com.adobe.cq.wcm.core.components.models.Teaser;
import com.day.cq.commons.DownloadResource;
import com.day.cq.wcm.api.Page;
Expand All @@ -39,11 +43,22 @@
@Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME , extensions = ExporterConstants.SLING_MODEL_EXTENSION)
public class TeaserImpl extends com.adobe.cq.wcm.core.components.internal.models.v1.TeaserImpl {

private static final Logger LOGGER = LoggerFactory.getLogger(TeaserImpl.class);
private static final String TITLE_DELEGATE = "titleDelegate";

/**
* The current component.
*/
@ScriptVariable
private Component component;

public final static String RESOURCE_TYPE = "core/wcm/components/teaser/v2/teaser";

@ScriptVariable
protected Page currentPage;

private Resource titleResource;

@Override
@Nullable
public Link getLink() {
Expand All @@ -57,6 +72,19 @@ public String getLinkURL() {
return super.getLinkURL();
}

public Resource getTitleResource() {
if (titleResource == null && component != null) {
String delegateResourceType = component.getProperties().get(TITLE_DELEGATE, String.class);
if (StringUtils.isEmpty(delegateResourceType)) {
LOGGER.error("In order for title rendering delegation to work correctly you need to set up the titleDelegate property on" +
" the {} component; its value has to point to the resource type of a title component.", component.getPath());
} else {
titleResource = new CoreResourceWrapper(request.getResource(), delegateResourceType, null, null);
}
}
return titleResource;
}

protected boolean hasImage() {
// As Teaser v2 supports inheritance from the featured image of the page, the current resource is wrapped and
// augmented with the inherited properties and child resources of the featured image.
Expand Down
Expand Up @@ -5,5 +5,6 @@
jcr:primaryType="cq:Component"
jcr:title="Teaser (v2) (work-in-progress)"
sling:resourceSuperType="core/wcm/components/image"
titleDelegate="core/wcm/components/title/v3/title"
imageDelegate="core/wcm/components/image/v3/image"
componentGroup=".wip"/>
Expand Up @@ -160,6 +160,10 @@
</imageDelegate>
</items>
</main>
<title
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/include"
path="core/wcm/components/title/v3/title/cq:design_dialog/content/items/tabs/items/sizes"/>
<styletab
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/include"
Expand Down
Expand Up @@ -137,67 +137,6 @@
fieldDescription="A pretitle that will be displayed above the Teaser's title."
fieldLabel="Pretitle"
name="./pretitle"/>
<titleGroup
granite:hide="${cqDesign.titleHidden}"
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/well">
<items jcr:primaryType="nt:unstructured">
<title
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
fieldDescription="A title to display as the headline for the teaser."
fieldLabel="Title"
name="./jcr:title"
value="${cqDesign._jcr_description}"/>
<titleType
granite:hide="${!cqDesign.showTitleType}"
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/select"
fieldLabel="Title Type"
name="./titleType"
granite:class="foundation-toggleable">
<items jcr:primaryType="nt:unstructured">
<def
jcr:primaryType="nt:unstructured"
text="(default)"
value=""/>
<h1
jcr:primaryType="nt:unstructured"
text="H1"
value="h1"/>
<h2
jcr:primaryType="nt:unstructured"
text="H2"
value="h2"/>
<h3
jcr:primaryType="nt:unstructured"
text="H3"
value="h3"/>
<h4
jcr:primaryType="nt:unstructured"
text="H4"
value="h4"/>
<h5
jcr:primaryType="nt:unstructured"
text="H5"
value="h5"/>
<h6
jcr:primaryType="nt:unstructured"
text="H6"
value="h6"/>
</items>
</titleType>
<titleFromLinkedPage
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
checked="{Boolean}false"
fieldDescription="When checked, populate the title with the linked page's title."
name="./titleFromPage"
text="Get title from linked page"
uncheckedValue="{Boolean}false"
value="{Boolean}true"/>
</items>
</titleGroup>
<descriptionGroup
granite:hide="${cqDesign.descriptionHidden}"
jcr:primaryType="nt:unstructured"
Expand Down Expand Up @@ -362,6 +301,10 @@
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/include"
path="core/wcm/components/image/v3/image/cq:dialog/content/items/tabs/items/asset"/>
<title
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/include"
path="core/wcm/components/title/v3/title/cq:dialog/content/items/tabs/items/properties"/>
</items>
</tabs>
</items>
Expand Down
Expand Up @@ -14,10 +14,5 @@
~ limitations under the License.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/-->
<sly data-sly-template.title="${@ teaser}">
<h2 class="cmp-teaser__title" data-sly-test.title="${teaser.title}" data-sly-element="${teaser.titleType}">
<a class="cmp-teaser__title-link"
data-sly-attribute="${teaser.link.htmlAttributes}"
data-sly-unwrap="${!teaser.link.valid || teaser.titleLinkHidden}"
data-cmp-clickable="${teaser.data ? true : false}">${title}</a>
</h2>
<div class="cmp-teaser__title" data-sly-test="${teaser.titleResource}" data-sly-resource="${teaser.titleResource}"></div>
</sly>
Expand Up @@ -20,4 +20,5 @@
jcr:title="Teaser"
sling:resourceSuperType="core/wcm/components/teaser/v2/teaser"
componentGroup="Core Components Examples"
titleDelegate="core/wcm/components/title/v3/title"
imageDelegate="core-components-examples/components/image"/>