2

Is there any way to make OOTB Component field optional in Child component in SmartEdit ?

For example, I extended CMSParagraphComponent by creating child component e.g. MyCustomParagraphComponent which extends CMSParagraphComponent.

OOTB CMSParagraphComponent -> content attribute is mandatory as defined in its CMS Structure API

<bean class="de.hybris.platform.cmsfacades.types.service.impl.DefaultComponentTypeAttributeStructure" p:typecode="CMSParagraphComponent" p:qualifier="content">
    <property name="populators">
        <set>
            <ref bean="richTextComponentTypeAttributePopulator" />
            <ref bean="requiredComponentTypeAttributePopulator" />
        </set>
    </property>
</bean>

requiredComponentTypeAttributePopulator makes this attribute mandatory. In addition, OOTB SmartEdit using cmsParagraphComponentValidator as well for backend validation.

Now I want to make content attribute optional for my custom MyCustomParagraphComponent

I tried creating new populator bean unRequiredComponentTypeAttributePopulator with required=false and assign it to content attribute of my custom component but that doesn’t work

Trying something like this ...

<bean id="unRequiredComponentTypeAttributePopulator" class="de.hybris.platform.cmsfacades.types.populator.RequiredComponentTypeAttributePopulator">
    <property name="required" value="false" />
</bean>

<bean class="de.hybris.platform.cmsfacades.types.service.impl.DefaultComponentTypeAttributeStructure" p:typecode="PromotionalBannerComponent" p:qualifier="content">
    <property name="populators">
        <set>
            <ref bean="unRequiredComponentTypeAttributePopulator" />
        </set>
    </property>
</bean>

But this is not working. It look like CMS Structure API works on only those attribute assigned directly to that component not parent one.

Then what is the correct way to do that ?

Free-Minded
  • 5,322
  • 6
  • 50
  • 93

1 Answers1

0

In your custom "facade-spring.xml", define the bean:

<bean id="optionalComponentTypeAttributePopulator"  class="de.hybris.platform.cmsfacades.types.populator.RequiredComponentTypeAttributePopulator">
    <property name="required" value="false" />
</bean>

Now, in your custom "facade-spring.xml", try overriding the bean of the Out of the Box:

<bean class="de.hybris.platform.cmsfacades.types.service.impl.DefaultComponentTypeAttributeStructure" p:typecode="CMSLinkComponent" p:qualifier="product">
    <property name="populators">
        <set>
            <ref bean="optionalComponentTypeAttributePopulator" />
        </set>
    </property>
</bean>

I have tested this locally and it works perfectly.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83