Expand my Community achievements bar.

SOLVED

How to customize OOTB Experience Fragment component

Avatar

Level 2

Hi,

I got a requirement to modify OOTB Experience Fragment component (not core component) to open it's picker on custom path. It means, by default this component opens picker box with /content/experience-fragments path, however I want to open this picker from /content/experience-fragments/brands path, so content author can select XF from this location only.

 

prithwi_0-1709237229514.png

Basically, I'm looking for a way to initialize this root parameter with custom path but I'm not able to figure out which library to extends or overlay. 

prithwi_1-1709238966939.png

 

Thanks.

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @prithwi 
One way is to write a clientlibs with category cq.dialog.authoring and based on your path(site), you can update the rootPath using javascript. 

Example of dialog ready event : https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/foundation-contentloaded-a... 



Arun Patidar

View solution in original post

8 Replies

Avatar

Level 10

@prithwi 

The root path is defined under below file 

/libs/cq/experience-fragments/editor/components/xffield/xffield.js --> Line 23

xffield folder is in blur color which means it is not allow to overlay this file


Imran__Khan_0-1709241956365.png


After making manual change in libs file 

Imran__Khan_1-1709242064332.png

 

Avatar

Level 2

Thanks @Imran__Khan for looking into this. As you said this libs path is protected so we can't overlay it. Is there a way to hook granite foundation registry to achieve this? I was looking into below documentation but not sure if this can be used to achieve my requirement.

https://developer.adobe.com/experience-manager/reference-materials/6-5/granite-ui/api/jcr_root/libs/...

Any suggestion would be appreciated. 

 

Thanks.

Avatar

Level 10

I don't know it will help as you don't want to overlay core component. But, overlay dialog is the only way and the recommended process and add rootPath property to /content or whichever path we wish.
Note: I looked into the OOTB library and it is not going to work to update path and it will create various issues while performing operations like copy, move, etc. Expeience fragment is tightly coupled to /content/experience-fragments folder.

 

/libs/core/wcm/components/experiencefragment/v2/experiencefragment 
Node: /libs/core/wcm/components/experiencefragment/v2/experiencefragment/cq:dialog/content/items/tabs/items/properties/items/columns/items/column/items/fragmentVariationPath

Imran__Khan_0-1709277051182.png

 

Avatar

Community Advisor

You need to overlay the experiencefragment _cq_dialog in your project and include the rootPath="/content/experience-fragments/brands" property within the fragmentVariationPath node.

<fragmentVariationPath jcr:primaryType="nt:unstructured"
  sling:resourceType="cq/experience-fragments/editor/components/xffield"
  granite:id="xfPicker"
  name="./fragmentVariationPath"
  fieldLabel="Variation"
  filter="folderOrVariant"
  propertyFilter="cq:xfShowInEditor"
  variant="web"
  rootPath="/content/experience-fragments/brands"
  fieldDescription="Choose the experience fragment variation to display."/>

 

Avatar

Level 10

@Mahedi_Sabuj As mentioned by @prithwi, he don't want to overlay anything from core components. 

Avatar

Level 2

Actually OOTB component is already used in many pages. So, I have to implement this feature in already used component as well. 

Thanks.

Avatar

Correct answer by
Community Advisor

Hi @prithwi 
One way is to write a clientlibs with category cq.dialog.authoring and based on your path(site), you can update the rootPath using javascript. 

Example of dialog ready event : https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/foundation-contentloaded-a... 



Arun Patidar

Avatar

Level 2

Thanks @arunpatidar. I have tried it and found working. Pasting full code that worked for me. 

(function ($, $document) {
    "use strict";
  
    $document.on("dialog-ready", function (e) {
      let expFragmentField = $("#xfPicker");
      if (expFragmentField && expFragmentField.length > 0) {
        const parameters = {};
        let src=$(expFragmentField).attr("pickersrc");
        // console.log("xf-picker src >>>>> " + src);

        let urlArr = src.split("?");
        let queryParams = urlArr[1].split("&");
  
        queryParams.forEach((p) => {
          let tokens = p.split("=");
          if (tokens && tokens.length > 1) {
            if (tokens[0] === "root") {
              parameters[tokens[0]] = tokens[1] + "brands";
            } else {
              parameters[tokens[0]] = tokens[1];
            }
          }
        });
        // console.log(parameters);
  
        let pickerSrcUrl = urlArr[0] + "?";
        Object.keys(parameters).forEach((key) => {
          pickerSrcUrl += key + "=" + parameters[key] + "&";
        });
  
        // console.log(pickerSrcUrl);
        $(expFragmentField).attr("pickersrc", pickerSrcUrl);
      }
    });
  })(jQuery, jQuery(document));