Skip to content

Instantly share code, notes, and snippets.

@LucGosso
Last active February 6, 2020 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LucGosso/e43a5d5e28d7aba14fcb3bc23680980e to your computer and use it in GitHub Desktop.
Save LucGosso/e43a5d5e28d7aba14fcb3bc23680980e to your computer and use it in GitHub Desktop.
Link to containing parent for media and blocks when not used. Blogg post: https://devblog.gosso.se/?p=1291
<?xml version="1.0" encoding="utf-8"?>
<module>
<!--clientResources>
<add name="epi-cms.widgets.base" path="Styles/Styles.css" resourceType="Style"/>
</clientResources-->
<dojo>
<!-- Add a mapping from site to ~/ClientResources/Scripts to the dojo loader configuration -->
<paths>
<add name="clientscripts" path="Scripts" />
</paths>
</dojo>
<clientModule initializer="clientscripts.parentcontainer">
<moduleDependencies>
<add dependency="CMS" type="RunAfter" />
</moduleDependencies>
</clientModule>
<assemblies>
<add assembly="*YourSiteAssemblyName*" />
</assemblies>
</module>
define(["dojo/_base/declare", "dojo/when",
"dojo/_base/lang", "epi/shell/_ContextMixin", "epi/dependency", "dojo/topic"],
function (declare, when, lang, _ContextMixin, dependency, topic) {
return declare([_ContextMixin],
{
initialize: function () {
topic.subscribe("/epi/shell/action/changeview/updatestate", lang.hitch(this, "_viewchanged"));
this.inherited(arguments);
},
_viewchanged: function (data) {
var contextService = dependency.resolve("epi.shell.ContextService");
//hack - using different loadtime becaus it loads different depending where you open from
loadtime = (data.viewName === "onpageedit") ? 1800 : 900;
this._contextChanged2(contextService.currentContext, loadtime);
},
_contextChanged2: function (newContext, loadtime) {
if (!newContext) {
return;
}
loadtime = loadtime > 100 ? loadtime : 700;
//only activate on media and block, think i found a combination
var activate = (newContext.capabilities.deleteLanguageBranch && newContext.capabilities.versionable/*Media*/ && !newContext.capabilities.canconfigureapproval) || newContext.capabilities.isBlock;
if (activate) {
var that = this;
setTimeout(
function () {
//hack to put it under the Type label (there is no pluginarea defined for this area)
var label = document.body.querySelectorAll("[data-dojo-attach-point='typeNode']");
if (label.length > 0 && !document.getElementById("parentBreadcrumbsTitle")) {
var span = label[0];
var li = document.createElement('li');
li.className = "epi-form-container__section__row";
li.innerHTML = '<label id="parentBreadcrumbsTitle"></label><span data-dojo-attach-point="languagesNode" class="epi-previewableTextBox-text dijitInline"><span id="parentBreadcrumb" class="epi-previewableTextBox-link epi-functionLink">' + newContext.parentLink + "</span></span>";
//this could be changed in future version, not so good
span.parentNode.parentNode.parentNode.parentNode.insertBefore(li, span.parentNode.parentNode.parentNode.nextSibling);
var registry = dependency.resolve("epi.storeregistry"),
store = registry.get("epi.cms.contentdata"),
query = store.query({
id: newContext.parentLink
});
query.then(function (data) {
if (data.capabilities.isContentFolder) {
document.getElementById("parentBreadcrumbsTitle").innerHTML = data.contentTypeName;
var parentid = data.ownerContentLink;
parentid = parentid ? parentid : data.contentLink;
document.getElementById("parentBreadcrumb").innerHTML = '<a href="#context=epi.cms.contentdata:///' + parentid + '">' + data.name + '</a>';
}
});
}
}, loadtime);
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment