Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Can't resolve dependency "epi.globalcommandregistry" when setting up a custom command

Vote:
 

I have the following javascript in the file ClientResources/Scripts/widgets/media/Mediacommands.js:

require(['dojo/aspect', 'epi/dependency', 'samples/media/MediaUpdateCommand'], function (aspect, dependency, MediaUpdateCommand) {

    //alert('registering');
    var handle,
		key = 'epi.cms.globalToolbar',
		registry = dependency.resolve('epi.globalcommandregistry'),
		callback = function (identifier, provider) {
		    if (identifier !== key) {
		        return;
		    }

		    provider.addCommand(new MediaUpdateCommand(), {
		        showLabel: true
		    });

		    handle.remove();
		};

    handle = aspect.after(registry, 'registerProvider', callback, true);
});

My module.config looks like this:


    
        
    
  
        
        
  
  
    
      
    
  
  
    
  

This is intended to add a button to the Editor toolbar, and *sometimes* works. However around 70% of the time I see the error Can't resolve dependency "epi.globalcommandregistry" in the console.

This corresponds to the line registry = dependency.resolve('epi.globalcommandregistry'), in the javascript above.

Is there any reason why the dependency can't be resolved at some times and more to the point, how can I ensure it's resolved every time?

Thanks,

Mark

#119097
Mar 20, 2015 15:51
Vote:
 

Hi!

I suggest that you create an init module on the client since this will make the code run at the right time. Here is a copy paste example from something I worked on recently:

Module.config:

<clientModule initializer="[your module class including namespace]">
<moduleDependencies>
<add dependency="CMS" type="Require RunAfter" />
</moduleDependencies>
</clientModule>

Client module sample:

define([
    // Pull in the patches. Not used here, just evaluated, since this is the first module loaded when starting the application.
    "dojo/_base/declare",
    "dojo/_base/lang",
    "epi/_Module",
    "epi/dependency",
    "instantTemplates/AddItemFromTemplateCommandProvider"
],

function (
    declare,
    lang,
    _Module,
    dependency,
    AddItemFromTemplateCommandProvider
) {

    return declare([_Module], {
        // summary:
        //		Template module implementation.
        //
        // tags:
        //      internal

        _settings: null,

        constructor: function (settings) {
            this._settings = settings;
        },

        initialize: function () {

            var commandregistry = dependency.resolve("epi.globalcommandregistry");

            //We need to wait for the viewsettings to initialized before creating the global toolbar command provider
            commandregistry.registerProvider("epi.cms.globalToolbar", new AddItemFromTemplateCommandProvider({templatesRoot : this._settings.templatesRoot}));
        }
    });
});



#119233
Mar 25, 2015 8:22
Vote:
 

Linus,

That did it for me (specifically the module.config settings) - thanks!.

#119583
Mar 30, 2015 12:57
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.