cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Default value for cms components

Former Member
942

Hi,

I've extended the ContentPage to add another attribute like this:

 <itemtype code="ContentPage" autocreate="false" generate="false">
     <attributes>
         <attribute type="java.lang.Boolean" qualifier="myBoolean">
             <defaultvalue>Boolean.TRUE</defaultvalue>
             <persistence type="property"/>
          </attribute>
     </attributes>
 </itemtype>

Now I want this flag to already be checked when I create a new content page in smartedit, but for me its always set to false. Does anyone know how to do this?

Thanks in advance

Accepted Solutions (0)

Answers (1)

Answers (1)

0 Kudos

Ok, i found it out myself.

For everybody searching:
The approach by the original poster works for the backoffice and would have been enough in pre-headless times.

For smartedit additional adjustments are necessary to make the change visible there too:

  • adjust the API Response to return the default value for the attribute
  • adjust the smartedit component to handle the attribute

In the case of a default value for a boolean attribute, smartedit is already prepared to handle it.
SeBooleanComponent.d.ts:

* @description
* Component responsible for generating custom toggle for the {@link genericEditorModule.service:GenericEditor genericEditor}.
*
* The following is an example of a possible field structures that can be returned by the Structure API for seBoolean to work:
* {
*   cmsStructureType: "Boolean",
*   qualifier: "someQualifier",
*   i18nKey: 'i18nkeyForSomeQualifier',
*   localized: false,
*   defaultValue: true
* } 
This means smartedit can already handle a boolean attribute „defaultValue“ with the values true / false.

To make this happen on the backend side

  • add a new property „defaultValue“ to ComponentTypeAttributeData
  • create a new populator that populates the ComponentTypeAttributeData with the defaultValue from the AttributeDescriptorModel
  • assign that populator to the attribute of the type this should be applied for.

To have a better idea, check out this video which describes a similar scenario: https://enable.cx.sap.com/media/Customizing+an+Attribute+Editor+in+SmartEdit+-+SAP+Commerce+Cloud/1_...