adobe / aem-core-wcm-components

Standardized components to build websites with AEM.
https://docs.adobe.com/content/help/en/experience-manager-core-components/using/introduction.html
Apache License 2.0
723 stars 737 forks source link

'Allowed Heading Elements' datasource enhancements #2706

Open danijelbasic opened 3 months ago

danijelbasic commented 3 months ago

Feature Request

For a custom component that has the following requirements: 1) a title and sections where each section has its own title (both the component and section titles are configured via the component dialog) 2) allowed headings for both the component title and the section titles should be set via the component policy

The current resource types core/wcm/components/commons/datasources/allowedheadingelements/v1 and core/wcm/components/title/v1/datasource/allowedtypes (backed by com.adobe.cq.wcm.core.components.internal.servlets.AllowedHeadingElementsDataSourceServlet) cannot be used to implement such requirement.

Is your feature request related to a problem? Please describe. Concrete example: I'd like to extend Accordion component with the option to configure a title and define allowed headings for that title (via the component policy). At the moment, Accordion component has the option to set the title for its items and allowed headings for these titles via the component policy.

The additional requirement can be easily achieved if: 1) Accordion design dialog is extended to include /libs/core/wcm/components/title/v3/title/cq:design_dialog/content/items/tabs/items/sizes 2) Accordion dialog is extended to include /libs/core/wcm/components/title/v3/title/cq:dialog/content/items/tabs/items/properties/items/columns/items/column/items/title /libs/core/wcm/components/title/v3/title/cq:dialog/content/items/tabs/items/properties/items/columns/items/column/items/types /libs/core/wcm/components/title/v3/title/cq:dialog/content/items/tabs/items/properties/items/columns/items/column/items/defaulttypes

Unfortunately, in com.adobe.cq.wcm.core.components.internal.servlets.AllowedHeadingElementsDataSourceServlet there's a "fallback" logic that actually hides heading types for Accordion title if heading types for Accordion item title is set. On another side, if nothing is set for allowed headings for Accordion item title then the allowed headings for Accordion title (if set) will be used instead.

String[] headingElements = props.get(PN_ALLOWED_HEADING_ELEMENTS, String[].class);
String[] allowedTypes = props.get(PN_ALLOWED_TYPES, String[].class);
String defaultHeadingElement = props.get(PN_DEFAULT_HEADING_ELEMENT, props.get(PN_DEFAULT_TYPE, StringUtils.EMPTY));
if (defaultHeadingElement.isEmpty() ) {
  defaultHeadingElement = props.get(PN_DEFAULT_TITLE_TYPE, StringUtils.EMPTY);
}
if (headingElements == null || headingElements.length == 0) {
  headingElements = allowedTypes;
}

Describe the solution you'd like Please get rid of the current logic and make com.adobe.cq.wcm.core.components.internal.servlets.AllowedHeadingElementsDataSourceServlet configurable with the names of the properties that hold 1) the list of allowed heading types 2) the default heading type

so the dialog definitions could look like this:

<accordionTitleTypes
  jcr:primaryType="nt:unstructured"
  sling:resourceType="granite/ui/components/coral/foundation/form/select"
  fieldLabel="Accordion Title Type / Size"
  name="./accordionTitleTypes">
  <datasource
    jcr:primaryType="nt:unstructured"
    sling:resourceType="core/wcm/components/title/v1/datasource/allowedtypes"
    allowedHeadingsPN="accordionTitleAllowedHeadings"
    defaultAllowedHeadingPN="accordionTitleDefaultAllowedHeading"/>
</accordionTitleTypes>

<accordionItemTitleTypes
  jcr:primaryType="nt:unstructured"
  sling:resourceType="granite/ui/components/coral/foundation/form/select"
  fieldLabel="Accordion Item Title Type / Size"
  name="./accordionItemTitleTypes">
  <datasource
    jcr:primaryType="nt:unstructured"
    sling:resourceType="core/wcm/components/title/v1/datasource/allowedtypes"
    allowedHeadingsPN="accordionItemTitleAllowedHeadings"
    defaultAllowedHeadingPN="accordionItemTitleDefaultAllowedHeading"/>
</accordionTitleTypes>

The servlet will consider only configured property names (possible to define fallback names allowedHeadingElements, and headingElement if nothing is set in the component dialog).

Are there alternatives? A clear and concise description of any alternative solutions or features you've considered.

Documentation Please have a look at the code snippet in the previous sections.