Customizing the childreneditor for custom components | Community
Skip to main content
Level 3
Aug 15, 2020 8:13 PM UTC
Solved

Customizing the childreneditor for custom components

Hi Everyone, can you provide me the steps to customize the childreneditor for custom components?

 

I followed the approach from accordion and carousel to do repeat in my component, but I am facing following issue -

 

org.apache.sling.api.resource.PersistenceException: Unable to commit changes to session.

 

Steps i followed -

  1. Made my component as cq:isContainer
  2. copied items tab from carousel to my custome component
    • core/wcm/components/commons/editor/dialog/childreneditor/v1/childreneditor
  3. copied cq:editConfig from Accordion with listeners
  4. included panelcontainer.js from accordion
  5. include below code for adding components

 

 

<sly data-sly-resource="${resource.path @ resourceType='wcm/foundation/components/parsys/newpar', appendPath='/*', decorationTagName='div', cssClassName='new section aem-Grid-newComponent'}" data-sly-test="${(wcmmode.edit || wcmmode.preview)}"></sly>​

 

 

FYI - I don't want to use the Accordion, Carousel or tab as my sling:resourceSuperType

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
arunpatidar
arunpatidarAccepted solution
New Participant
Aug 16, 2020 1:30 PM UTC

You can use child editor for custom components similar to the core components. 

I did it before for custom navigation component but unfortunately I don't have the complete package.

 

Editorhook.js

(function(channel) { "use strict"; channel.on("cq-editor-loaded", function(event) { if (window.CQ && window.CQ.CoreComponents && window.CQ.CoreComponents.panelcontainer && window.CQ.CoreComponents.panelcontainer.v1 && window.CQ.CoreComponents.panelcontainer.v1.registry) { window.CQ.CoreComponents.panelcontainer.v1.registry.register({ name: "cmp-navigation", selector: ".cmp-navigation", itemSelector: "[data-cmp-hook-navigation='navpanel']", itemActiveSelector: ".cmp-navigation__navigation-item.is-active" }); } }); })(jQuery(document));

 

extraclientlibs for navigation component dialog

(function($, $document) { "use strict"; $(document).ready(function() { const NAV_SELECTOR = '.cmp-panelselector.is-open .cmp-panelselector__table tr'; const NAVIGATIOIN_ITEM_TITLE = 'Navigation Item'; const NOT_ACTIVE_NAVITEM_CLASS='navItemEditNotActiveItem'; const NAV_Not_ACTIVE_ITEM_SELECTOR ='.'+ NOT_ACTIVE_NAVITEM_CLASS; const NOT_ACTIVE_ITEM_CLASS = 'notActiveItem'; const ITEM_ACTIVE_CLASS = 'is-active'; const CONTENT_IFRAME_SELECTOR ='#ContentFrame'; $(document).on('click', NAV_SELECTOR, function() { var $this = $(this); var item = $this.data('id'); var navItemSelector = '.cq-Overlay.cq-Overlay--component.cq-Overlay--container.cq-draggable.cq-droptarget.is-selected.is-active div.cq-droptarget[data-path="' + item + '"]'; var $navItem = $(navItemSelector); if ($navItem.attr('title') == NAVIGATIOIN_ITEM_TITLE) { $(NAV_Not_ACTIVE_ITEM_SELECTOR).find('div').removeClass(NOT_ACTIVE_ITEM_CLASS); $($navItem).siblings().addClass(NOT_ACTIVE_NAVITEM_CLASS); $navItem.removeClass(NOT_ACTIVE_NAVITEM_CLASS); $(NAV_Not_ACTIVE_ITEM_SELECTOR).find('div').addClass(NOT_ACTIVE_ITEM_CLASS); var contentItem = $this.data('name'); if (typeof contentItem !== 'undefined' || contentItem !== null) { contentItem = contentItem.replace('_', ''); var contentItemSelector = '.cmp-navigation_author .cmp-navigation__navigation--item[data-nav-item="' + contentItem + '"]'; $(CONTENT_IFRAME_SELECTOR).contents().find('.cmp-navigation_author .cmp-navigation__navigation--item').removeClass(ITEM_ACTIVE_CLASS); $(CONTENT_IFRAME_SELECTOR).contents().find(contentItemSelector).addClass(ITEM_ACTIVE_CLASS); } } }) }); })($, $(document));

 

 

HTL

<div class="cmp-navigation__navigation--item" data-cmp-hook-navigation="navpanel" data-nav-item="item${linkList.index}"> <sly data-sly-resource="${resourcePath @ resourceType='myapp/components/structure/header/navigation/navigation-item'}"/> </div>
Arun Patidar

8 replies

arunpatidar
New Participant
Feb 2, 2023 4:08 PM UTC
Arun Patidar
Employee
Aug 16, 2021 8:13 PM UTC

Hello @ramaem12 ! do you have the whole example of this implementation? how did you implement the model for this component? Have you done this for SPA?

Translate
arunpatidar
New Participant
Feb 9, 2022 4:54 PM UTC

Hi @gonzalo_calandria 

I implemented for trdiational AEM implementation but not for SPA.

 

I have shared the code in above example. I will try to create a generic solution and share with community.

Translate
Arun Patidar
arunpatidar
arunpatidarAccepted solution
New Participant
Aug 16, 2020 1:30 PM UTC

You can use child editor for custom components similar to the core components. 

I did it before for custom navigation component but unfortunately I don't have the complete package.

 

Editorhook.js

(function(channel) { "use strict"; channel.on("cq-editor-loaded", function(event) { if (window.CQ && window.CQ.CoreComponents && window.CQ.CoreComponents.panelcontainer && window.CQ.CoreComponents.panelcontainer.v1 && window.CQ.CoreComponents.panelcontainer.v1.registry) { window.CQ.CoreComponents.panelcontainer.v1.registry.register({ name: "cmp-navigation", selector: ".cmp-navigation", itemSelector: "[data-cmp-hook-navigation='navpanel']", itemActiveSelector: ".cmp-navigation__navigation-item.is-active" }); } }); })(jQuery(document));

 

extraclientlibs for navigation component dialog

(function($, $document) { "use strict"; $(document).ready(function() { const NAV_SELECTOR = '.cmp-panelselector.is-open .cmp-panelselector__table tr'; const NAVIGATIOIN_ITEM_TITLE = 'Navigation Item'; const NOT_ACTIVE_NAVITEM_CLASS='navItemEditNotActiveItem'; const NAV_Not_ACTIVE_ITEM_SELECTOR ='.'+ NOT_ACTIVE_NAVITEM_CLASS; const NOT_ACTIVE_ITEM_CLASS = 'notActiveItem'; const ITEM_ACTIVE_CLASS = 'is-active'; const CONTENT_IFRAME_SELECTOR ='#ContentFrame'; $(document).on('click', NAV_SELECTOR, function() { var $this = $(this); var item = $this.data('id'); var navItemSelector = '.cq-Overlay.cq-Overlay--component.cq-Overlay--container.cq-draggable.cq-droptarget.is-selected.is-active div.cq-droptarget[data-path="' + item + '"]'; var $navItem = $(navItemSelector); if ($navItem.attr('title') == NAVIGATIOIN_ITEM_TITLE) { $(NAV_Not_ACTIVE_ITEM_SELECTOR).find('div').removeClass(NOT_ACTIVE_ITEM_CLASS); $($navItem).siblings().addClass(NOT_ACTIVE_NAVITEM_CLASS); $navItem.removeClass(NOT_ACTIVE_NAVITEM_CLASS); $(NAV_Not_ACTIVE_ITEM_SELECTOR).find('div').addClass(NOT_ACTIVE_ITEM_CLASS); var contentItem = $this.data('name'); if (typeof contentItem !== 'undefined' || contentItem !== null) { contentItem = contentItem.replace('_', ''); var contentItemSelector = '.cmp-navigation_author .cmp-navigation__navigation--item[data-nav-item="' + contentItem + '"]'; $(CONTENT_IFRAME_SELECTOR).contents().find('.cmp-navigation_author .cmp-navigation__navigation--item').removeClass(ITEM_ACTIVE_CLASS); $(CONTENT_IFRAME_SELECTOR).contents().find(contentItemSelector).addClass(ITEM_ACTIVE_CLASS); } } }) }); })($, $(document));

 

 

HTL

<div class="cmp-navigation__navigation--item" data-cmp-hook-navigation="navpanel" data-nav-item="item${linkList.index}"> <sly data-sly-resource="${resourcePath @ resourceType='myapp/components/structure/header/navigation/navigation-item'}"/> </div>
Translate
Arun Patidar
ramaem12Author
Level 3
Aug 16, 2020 8:47 PM UTC
Hi Arun, did you add any sling:resourceSuperType for your custome navigation component?
Translate
ChitraMadan
New Participant
Aug 15, 2020 10:14 PM UTC

Hi @ramaem12,

 

Please look at the below thread for your issue:

https://github.com/adobe/aem-core-wcm-components/issues/696

 

There is an open enhancement request for enabling children editor component to be made available to use on its own

The children editor which can be used with the core Carousel should be available by itself for use with container components #985

 

Hope this helps!!

Translate