A while back, we hatched the idea to create a new Marketplace module based on our experience and the feedback of editors with regards to content management in sites that are both heavy on amount of hosted sites and the available languages.
All of that and much more detailed information with regards to the EasyLingo module can be found on Gert Gullentops blog here: http://ggullentops.blogspot.be/2016/08/easylingo.html
However, the first version only featured an integration into the Content Editor as a new bar in your editing pane of the selected item.
We decided to up our game a little and introduce our new functionality into the Experience Editor.
My first idea was that this would go rather smoothly, because, let's face it, all I had to do was look at how Sitecore does it now and find a way to display the same HTML we were already rendering into the Content Editor. So, how hard could it be?
Note that I have no (zero) experience on creating or using Speak components offered by or through Sitecore.
First steps and approachMy first, somewhat naive idea was to go into doc.sitecore and find the tutorial, how-to or whatever that would guide me into realizing my goal. Turns out that the doc.sitecore site is either really good at hiding that kind of information or (as it might turn out), my searching skills are well below par.
My next idea was to go into stackexchange or the community and look for someone who had had the same challenge before him/her and learn from that. Unfortunately, the same conclusion as mentioned above applies here.
I then decided to dive head first into the Sitecore Core DB, all the relevant DLL's and the config files.
This last approach was the one that got me there in the end, but not without some pitfalls and concerns on how I had to approach this issue. As well as some support from, well..., Sitecore support. (Thanks Andrey Krupskiy)
Inspecting Sitecore Speak as-isI decided to have the added functionality displayed in a control bar. Much in the same way as the Navigation Bar is shown as a control in the Experience Editor. So, in theory, if I would look into the core and find out how this one is configured I should be able to derive what to do next.
And that is where I got stuck the first time. Turns out that Sitecore still supports Sheer UI next to Speak, but Speak is enabled by default. This means that everything you find in the core definitions on the ribbons are configured to handle both scenarios...
And that is where my confusion set in... I noticed that on the Core configuration item for the navigation bar, there was a command defined onclick : "webedit:toggletreecrumb".
However, everything this command referred to based itself on Sheer UI. And all the HTML that I was inspecting in the frontend of my Sitecore dummy project was rendering Speak controls.
So, just to be clear: Everything worked out in the end. And with the information below I hope to provide ample insight in how you could go ahead and (ab)use the Speak functionalities to get your own speak interface up and running.
Step by Step guideI've tried to walk through this step by step without makeing too many awkward jumps. I'll try to summarive at the bottom to give insight on which items/files/configs are required to go forward.
Showing the toggle button on the View chunk of your ribbonFirst things first; we needed this bar to be toggled on and off. Exactly like any of the other (optional) bars. To do this:
- Navigate to the Core database
- Navigate into: /sitecore/content/Applications/WebEdit/Ribbons/WebEdit/View/Show
- Create (or copy) a new "Small Check Button"
- Ignore the Click property, but do fill in the Header, Tooltip & ID value (smells like best practice doesn't it)
- Modify the Rendering (raw values) to adhere to the code block below:
Not on the above, obviously you can choose whichever path you see fit for the JS file as well as the registry key you choose to work with.
Making the toggle button actually workThe above made sure you got a checkbox that will be able to toggle your bar in and out of the experience editor. But it is time to hook up that JS file and show some first bar to render.
Let's start with creating the JS file we just referred to from our toggle button:
The above JS can now be executed successfully but doesn't have any clue on what to toggle visible as we have not yet defined the YOURRIBBONBAR anywhere.. Time to head back down into the Core db of Sitecore.
- Navigate to the Core database
- Navigate into: /sitecore/client/Applications/ExperienceEditor/Common/Layouts/Renderings/Ribbon/
- Create a new Folder: YOURBAR
- Create a new "View Rendering" in the newly created folder.
- Fill in the Path field with a reference into your cshtml file, which forexample could be here:
Now, in order for this control to be rendered, you need to create the control extension class:
And in turn, this control extension class requires a (duh) control to render:
As you can see. this control in itself hardly does anything at all. It just renders some Nav tag and applies a display=none to a div the is included. But the magic start to happen here when it, in the InitializeControl method registers your final (phew, are we almost there?) JS and CSS files that will handle the actual bar content generation.
So.... That was easy wasn't it? All we had to do is register some things, make some classes and bam, we have...
well nothing really at this point...
We still need to define what is to come in our JS file and make sure we are able to call our backend code. And remember that View Rendering we created? We still need to make sure that gets used somewhere from Sitecore.
Bringing all the final block togetherLet us start of with doing the last modification we need to do in the Core database to make sure that our ViewRendering is displayed correctly.
- Navigate into the Core database
- Navigate into this item: /sitecore/client/Applications/ExperienceEditor/Ribbon
- Go into the Renderings field of this item
- Add a reference to your ViewRendering ID
The 'ph' (placeholder) can remain the same, just make sure to refer to the right ViewRendering and create a unique uid (untested what happens if it is not unique, but lets play safe)...
And finally only a few steps remain. The sample of YOURBAR.JS and how to call your own business logic through Speak calls.
YOURBAR.JS as stored under ...sitecore\shell\client\Sitecore\Speak\Ribbon\Controls\YOURBAR:
I have purposely not included the CSS file to which I refer... This depends on a case by case scenario so it has no added value in placing it here. You surely spotted all the css class references throughout the code by now, so that should be clear in itself.
Css files are stored under: .\sitecore\shell\client\Sitecore\Speak\Ribbon\Assets\Generated
So, that kind of concludes the various steps needed to get this additional bar rendered. One last (somewhat optional) step remains and that is the part where we actually call the backend through a Speak command
Speak Commands from JSThe block below is the JS part that actually uses the context to call the Speak command through a given context that can be set up with a variety of parameters.
This "YOURSPEAKCOMMAND" needs to be registered into the Sitecore speak config and this is done here:
And the commandclass definition:
Do note that Sitecore ships with a whole lot of available SpeakCommands that you are free to call. This offered set is already very rich and diverse so check it out first before you start to make your own specific command. Although, in a lot of cases, this will prove to be the only way.
SummaryI honestly hope the above helped you either create your own bar of extra piece of Experience Editor Speak based component or has at least tought you on the different steps that may be needed and the skills required to develop this.
It was a much rougher patch then I initially expected but it worked out in the end and I have to say that I like the Speak calls especially. There is something clean about doing those very distinct, single-purpose calls into your backend that I liked.
But the list of files that were required to be changed or created is quite lengthy:
- XBar.js + XBar.css (or at least in most cases)
- ControlsExtension to register your XBarControl
- ShowXBar Sitecore item checkbox control
- XBar Viewrendering control
- Ribbon item to visualize the XBar
And why did I start calling everything XBar here? I'm not really sure, just call me chaotic.
Kind regards and thanks for the read.