-
Notifications
You must be signed in to change notification settings - Fork 64
V2 version of Title #1292
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
V2 version of Title #1292
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| ~ Copyright 2024 Adobe | ||
| ~ | ||
| ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
| ~ you may not use this file except in compliance with the License. | ||
| ~ You may obtain a copy of the License at | ||
| ~ | ||
| ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
| ~ | ||
| ~ Unless required by applicable law or agreed to in writing, software | ||
| ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
| ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| ~ See the License for the specific language governing permissions and | ||
| ~ limitations under the License. | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ | ||
| package com.adobe.cq.forms.core.components.internal.models.v2.form; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| import javax.annotation.PostConstruct; | ||
|
|
||
| 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.*; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| import com.adobe.aemds.guide.utils.GuideUtils; | ||
| import com.adobe.cq.export.json.ComponentExporter; | ||
| import com.adobe.cq.export.json.ExporterConstants; | ||
| import com.adobe.cq.forms.core.components.datalayer.FormComponentData; | ||
| import com.adobe.cq.forms.core.components.internal.Heading; | ||
| import com.adobe.cq.forms.core.components.internal.form.FormConstants; | ||
| import com.adobe.cq.forms.core.components.internal.form.ReservedProperties; | ||
| import com.adobe.cq.forms.core.components.models.form.FormTitle; | ||
| import com.adobe.cq.forms.core.components.util.AbstractFormComponentImpl; | ||
| import com.adobe.cq.forms.core.components.util.ComponentUtils; | ||
| import com.day.cq.commons.jcr.JcrConstants; | ||
| import com.day.cq.wcm.api.WCMMode; | ||
|
|
||
| @Model( | ||
| adaptables = { SlingHttpServletRequest.class, Resource.class }, | ||
| adapters = { FormTitle.class, ComponentExporter.class }, | ||
| resourceType = FormConstants.RT_FD_FORM_TITLE_V2) | ||
| @Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION) | ||
|
|
||
| public class TitleImplV2 extends AbstractFormComponentImpl implements FormTitle { | ||
|
|
||
| /** | ||
| * The current resource. | ||
| */ | ||
| @SlingObject | ||
| private Resource resource; | ||
|
|
||
| @ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL) | ||
| @Nullable | ||
| private String type; | ||
|
|
||
| @ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = JcrConstants.JCR_TITLE) | ||
| @Nullable | ||
| private String title; | ||
|
|
||
| @ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = ReservedProperties.PN_HTML_ELEMENT_TYPE_V2) | ||
| @Nullable | ||
| private String format; | ||
|
Collaborator
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. You should only inject things required for title here, other base properties/method should derive from parent class |
||
|
|
||
| private Heading heading; | ||
|
|
||
| /** | ||
| * Translation of the title property | ||
| */ | ||
|
|
||
| @PostConstruct | ||
| private void initModel() { | ||
| if (request != null && i18n == null) { | ||
| i18n = GuideUtils.getI18n(request, resource); | ||
pavi41 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| if (StringUtils.isBlank(title)) { | ||
| Resource formContainerResource = ComponentUtils.getFormContainer(resource); | ||
| if (formContainerResource != null) { | ||
| title = formContainerResource.getValueMap().get("title", String.class); | ||
| } | ||
| } | ||
| if (heading == null) { | ||
| heading = Heading.getHeading(format); | ||
| if (heading == null && currentStyle != null) { | ||
| heading = Heading.getHeading(currentStyle.get(PN_DESIGN_DEFAULT_FORMAT, String.class)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String getText() { | ||
| return getValue(); | ||
| } | ||
|
|
||
| @Override | ||
| public String getValue() { | ||
| String propertyName = JcrConstants.JCR_TITLE; | ||
| String propertyValue = title; | ||
| boolean editMode = true; | ||
| if (request != null) { | ||
| editMode = WCMMode.fromRequest(request) == WCMMode.EDIT || WCMMode.fromRequest(request) == WCMMode.DESIGN; | ||
| } | ||
| if (editMode) { | ||
| return propertyValue; | ||
| } | ||
| if (StringUtils.isBlank(propertyValue)) { | ||
| return null; | ||
| } | ||
| return ComponentUtils.translate(propertyValue, propertyName, resource, i18n); | ||
| } | ||
|
|
||
| public String getHTMLElementType() { | ||
| if (heading != null) { | ||
| return heading.getElement(); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @NotNull | ||
| protected FormComponentData getComponentData() { | ||
| return super.getComponentData(); | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return null; | ||
|
Collaborator
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. Name is mandatory if a component is a form component, please check other implementation. We should also expose this in dialog
Contributor
Author
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. Implemented!
Collaborator
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. Why the title component should have a name. We have the chance to enable unnamed fields now, though we do not need to expose it but we can fix in our code wherever we have a hard restriction on name property
Collaborator
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.
In the core components, the name is mandatory as per the initial design, even though af-core does not enforce this requirement. While we can remove the name from the title component, doing so would prevent dynamic changes to the title component's text. Currently, we don't have a use case for this dynamic capability, so I'm okay with not implementing it. |
||
| } | ||
|
|
||
| @Override | ||
| public @NotNull Map<String, Object> getProperties() { | ||
| Map<String, Object> customProperties = super.getProperties(); | ||
| customProperties.put(ReservedProperties.PN_HTML_ELEMENT_TYPE_V2, getHTMLElementType()); | ||
| return customProperties; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| ~ Copyright 2024 Adobe | ||
| ~ | ||
| ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
| ~ you may not use this file except in compliance with the License. | ||
| ~ You may obtain a copy of the License at | ||
| ~ | ||
| ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
| ~ | ||
| ~ Unless required by applicable law or agreed to in writing, software | ||
| ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
| ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| ~ See the License for the specific language governing permissions and | ||
| ~ limitations under the License. | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ | ||
|
|
||
| //Previously, we were using the model of sites. However, the requirement now includes | ||
| // adding some properties, such as fieldtype. Therefore, we have used the model of sites | ||
| // and made the necessary changes to it. | ||
|
|
||
| package com.adobe.cq.forms.core.components.models.form; | ||
|
|
||
| // import org.jetbrains.annotations.Nullable; | ||
| import org.osgi.annotation.versioning.ConsumerType; | ||
|
|
||
| import com.adobe.cq.forms.core.components.internal.form.ReservedProperties; | ||
| import com.fasterxml.jackson.annotation.JsonIgnore; | ||
|
|
||
| // import com.adobe.cq.wcm.core.components.commons.link.Link; | ||
| // import com.adobe.cq.forms.core.components.models.form.BaseConstraint.Type; | ||
|
|
||
| /** | ||
| * Defines the form {@code Title} Sling Model used for the {@code /apps/core/fd/components/form/title/v2/title} component. | ||
| * | ||
| * @since com.adobe.cq.forms.core.components.models.form 5.5.3 | ||
| */ | ||
| @ConsumerType | ||
| public interface FormTitle extends FormComponent { | ||
|
Collaborator
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. Please mention in comments on why this was copied from WCM
Contributor
Author
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. Done!
Collaborator
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. Please add java doc for all functions, interfaces
Contributor
Author
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. Implemented! |
||
|
|
||
| /** | ||
| * Returns the HTML element type (h1-h6) used for the markup. | ||
| * | ||
| * @return the element type | ||
| * @since com.adobe.cq.forms.core.components.models.form 5.5.3; | ||
| */ | ||
| @JsonIgnore | ||
| default String getHTMLElementType() { | ||
| return null; | ||
| } | ||
|
|
||
| String PN_DESIGN_DEFAULT_FORMAT = ReservedProperties.PN_TYPE; | ||
|
|
||
| /** | ||
| * Returns the text to be displayed as title. | ||
| * | ||
| * @return the title's text | ||
| */ | ||
| @JsonIgnore | ||
| default String getText() { | ||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves the text value to be displayed. | ||
| * | ||
| * @return the text value to be displayed, or {@code null} if no value can be returned | ||
| * @since com.adobe.cq.forms.core.components.models.form 5.5.3; | ||
| */ | ||
| default String getValue() { | ||
| return null; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,7 @@ | |
| import org.apache.sling.api.resource.ValueMap; | ||
| import org.apache.sling.models.annotations.Default; | ||
| import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy; | ||
| import org.apache.sling.models.annotations.injectorspecific.ScriptVariable; | ||
| import org.apache.sling.models.annotations.injectorspecific.SlingObject; | ||
| import org.apache.sling.models.annotations.injectorspecific.ValueMapValue; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
@@ -62,6 +63,7 @@ | |
| import com.adobe.cq.wcm.core.components.util.ComponentUtils; | ||
| import com.day.cq.i18n.I18n; | ||
| import com.day.cq.wcm.api.WCMMode; | ||
| import com.day.cq.wcm.api.designer.Style; | ||
| import com.fasterxml.jackson.annotation.JsonIgnore; | ||
| import com.fasterxml.jackson.annotation.JsonInclude; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
|
@@ -108,6 +110,10 @@ public class AbstractFormComponentImpl extends AbstractComponentImpl implements | |
| @Nullable | ||
| protected String dorColspan; | ||
|
|
||
| @ScriptVariable(injectionStrategy = InjectionStrategy.OPTIONAL) | ||
| @Nullable | ||
| protected Style currentStyle; | ||
|
Collaborator
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. Please get ride of @JsonIgnore from here, it should be part of getters only
Contributor
Author
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. Removed! |
||
|
|
||
| /** | ||
| * Returns dorBindRef of the form field | ||
| * | ||
|
|
@@ -534,4 +540,5 @@ public Map<String, Object> getDorProperties() { | |
| } | ||
| return customDorProperties; | ||
| } | ||
|
|
||
| } | ||
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.
This should come from parent, you don't need to write here
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.
Defined variable is private in parent class as well also it doesn't contain any getter setter so that we can call.