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
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ private FormConstants() {
/** The resource type for title v1 */
public static final String RT_FD_FORM_TITLE_V1 = RT_FD_FORM_PREFIX + "title/v1/title";

/** The resource type for title v2 */
public static final String RT_FD_FORM_TITLE_V2 = RT_FD_FORM_PREFIX + "title/v2/title";

/** The resource type for submit button v1 */
public static final String RT_FD_FORM_SUBMIT_BUTTON_V1 = RT_FD_FORM_PREFIX + "actions/submit/v1/submit";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ private ReservedProperties() {
public static final String PN_OPTIONS_RICH_TEXT = "areOptionsRichText";
public static final String PN_EXCLUDE_FROM_DOR = "excludeFromDor";
public static final String PN_MANDATORY = "mandatory";
public static final String PN_HTML_ELEMENT_TYPE_V2 = "fd:htmlelementType";
private static final Set<String> reservedProperties = aggregateReservedProperties();

private static Set<String> aggregateReservedProperties() {
Expand Down
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;
Copy link
Collaborator

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

Copy link
Contributor Author

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.


@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;
Copy link
Collaborator

Choose a reason for hiding this comment

The 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);
}
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;
Copy link
Collaborator

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented!

Copy link
Collaborator

@vdua vdua Jul 10, 2024

Choose a reason for hiding this comment

The 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

Copy link
Collaborator

Choose a reason for hiding this comment

The 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

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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please mention in comments on why this was copied from WCM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add java doc for all functions, interfaces

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Expand Up @@ -35,7 +35,7 @@
* </p>
*/

@Version("5.4.3") // aligning this with release/650 since af2-rest-api is compiled with 5.2.0 in release/650
@Version("5.5.3") // aligning this with release/650 since af2-rest-api is compiled with 5.2.0 in release/650
package com.adobe.cq.forms.core.components.models.form;

import org.osgi.annotation.versioning.Version;
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -108,6 +110,10 @@ public class AbstractFormComponentImpl extends AbstractComponentImpl implements
@Nullable
protected String dorColspan;

@ScriptVariable(injectionStrategy = InjectionStrategy.OPTIONAL)
@Nullable
protected Style currentStyle;
Copy link
Collaborator

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed!


/**
* Returns dorBindRef of the form field
*
Expand Down Expand Up @@ -534,4 +540,5 @@ public Map<String, Object> getDorProperties() {
}
return customDorProperties;
}

}
Loading