3

I have a question or maybe a misunderstanding in regards to Edit Frames.

Some of my renderings use rendering parameters templates that work well when I choose Edit Component Properties in Experience Editor. However, if I add an edit frame (e.g. Html.EditFrame) to my renderings the Edit Component Properties button no longer seems to work. I have tried duplicating the default button and been trying to use a small edit frame button with different variations of commands like chrome:rendering:properties, chrome:common:edititem({command:"webedit:editrenderingproperties"}), and webedit:editrenderingproperties with no luck so far.

Is there a way to enable/call Edit Component Properties with my Edit Frames?

e.g. This button works fine without an edit frame, but i cant get it to work in an edit frame The Edit Component Properties button

6
  • Have you added the fields those needs to be shown in the Edit Frame? Like in the core database, where you added the button, there is a field called Fields where we need to add the Template Field ID. Commented May 25, 2022 at 6:43
  • Yes edit frames work fine using the fields specified by the datasource. I'm talking about the button called Edit Component Properties that shows by default in a dropdown on the right. When I use an edit frame and add that button from the default it is not triggering anything. So Im wanting the user to see a button to quickly edit the item in the datasource and additionally give them a quick option to change the rendering parameters via the parameters template (which would not be the datasource for the edit frame).
    – DrewG
    Commented May 25, 2022 at 6:45
  • Can't you work with Custom Experience Button? If you want the user to edit a field? That will show you this option. Commented May 25, 2022 at 8:07
  • @DrewG if you are using Glass Mapper 5 then you can have a look at my answer to this question and use the GM edit frame. In my component rendering parameter were working in the GM edit frame and it was working fine. sitecore.stackexchange.com/questions/13936/… Commented May 25, 2022 at 12:48
  • 1
    @HimmatSinghDulawat Hi no we are not using Glassmapper, we are using Fortis though it doesnt have an option for css class on edit frames so i stuck with the default. Ill have a look at that project to see if anything can be learned from it.
    – DrewG
    Commented May 25, 2022 at 15:48

1 Answer 1

3

So it appears that the root of the issue is that Edit Frame uses a different Chrome Type than a rendering and the Edit Frame Chrome Type does not implement chrome:rendering:properties or any other relevant command.

Rendering Chrome Type: shell\Applications\Page Modes\ChromeTypes\RenderingChromeType.js

Edit Frame Chrome Type: shell\Applications\Page Modes\ChromeTypes\EditFrameChromeType.js

EditFrameChromeType only handles 2 messages for edit frame. I was able to adjust the handlers from RenderingChromeType to work on the EditFrameChromeType. Here's the updated EditFrameChromeType.js I used that allows me to use the default button for Edit Component Properties on an edit frame.

Sitecore.PageModes.ChromeTypes.EditFrame = Sitecore.PageModes.ChromeTypes.ChromeType.extend({
  constructor: function() {
    this.base();
    this._editFrameUpdating = false;
    this.fieldsChangedDuringFrameUpdate = false;
  },
  
  handleMessage: function(message, params) {
    switch (message) {
      case "chrome:editframe:updatestart":
        this.updateStart();
        break;
      case "chrome:editframe:updateend":
        this.updateEnd();
        if (Sitecore.WebEditSettings.autoSaveOnEditFrame) {
            ExperienceEditor.ribbonDocument().querySelector('[data-sc-id="QuickSave"]').click();
        }
        break;
      case "chrome:rendering:properties":
        this.editProperties();
        break;
      case "chrome:rendering:propertiescompleted":
        this.editPropertiesCompleted();
        break;
    }
  },

  isEnabled: function() {
    return $sc.inArray(Sitecore.PageModes.Capabilities.edit, Sitecore.PageModes.PageEditor.getCapabilities()) > -1 && this.base();
  },

  key: function() {
    return "editframe";
  },

  load: function() {
  },

  updateStart: function() {  
    this._editFrameUpdating = true;
    this.fieldsChangedDuringFrameUpdate = false;    
  },

  updateEnd: function() {
    if (this.fieldsChangedDuringFrameUpdate) {
      this.chrome.element.addClass("scWebEditFrameModified");      
    }

    this._editFrameUpdating = false;
    this.fieldsChangedDuringFrameUpdate = false;
  },

  editProperties: function() {
    var placeholder = this.getPlaceholder();
    var rendering = this.getRendering();
    if (placeholder && rendering) {
      placeholder.type.editProperties(rendering);
    }
  },

  editPropertiesCompleted: function() {
    var placeholder = this.getPlaceholder();
    var rendering = this.getRendering();
    if (placeholder && rendering) {
      placeholder.type.editPropertiesResponse(rendering);
    }
  },
  uniqueId: function() {    
    var rendering = this.getRendering();
    if(!rendering){
      throw "Unable to find rendering for edit frame!";
    }
    return rendering.openingMarker().attr("id").substring(2);
  },
  getPlaceholder: function() {
    var placeholder = this.getContainerByType('placeholder', null, 1, 4);
    return placeholder;
  },
  
  getRendering: function() {
    var rendering = this.getContainerByType('rendering', null, 1, 4);
    return rendering;
  },

  getContainerByType: function (typeKey, itm, iteration, maxIterations) {
    itm = itm || this.chrome.parent(false, false);
    if (!itm) {
      return null;
    }
    if(itm.type.key() == typeKey){
      return itm;
    }
    var parentElement = itm.parent();
    if (!parentElement || parentElement.type.key() != typeKey) {
      if(iteration > maxIterations) {
        console.warn(itm.element);
        throw "EditFrame must have " + typeKey + " chrome as its parent. Got '" + itm.type.key() + "' instead";
      }
      return this.getContainerByType(typeKey, parentElement, iteration + 1, maxIterations);
    }
    return parentElement;
  }
});

I basically just extended the getPlaceholder logic that checks the parent to crawl recursively and get renderings and placeholders. That let me access the methods I needed and emulate the context of the rendering.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.