Contribution: Moddle extensions as plugins

Good morning,
I would like to share this small contribution to Camunda modeler code before making a pull request. We would like to add new attributes to bpmn using a different namespace. There is an issue on gitHub for this enhancement but, as far as I know, it’s not yet implemented. This is the small fork I made.

The only file I edited is bpmn-editor.js in /client/lib/app/editor folder, handling moddles as another key for the plugin object.

So, what I made so far is simply edit the BpmnJS object initialization adding additional moddles given by a new plugin type called ‘ bpmn.modeler.additionalModdles’ in order to maintain the same approach.

The instruction (see code in the fork) this.plugin.get(‘bpmn.modeler.additionalModdles’) returns an array of each property that has to be added to the old { camunda: camundaModdlePackage} object, which is done in the ‘for’ loop.

In order to add moddle plugins, the camunda-modeler-plugin-helpers has to be extended too, adding a new function for this new type, in the following way:

	// new function in  camunda-modeler-plugin-helpers
	function registerModdlePlugin(moddle) {
		registerClientPlugin(moddle, ‘bpmn.modeler.additionalModdles’);
	}
...
// client.js plugin example
var registerModdlePlugin = require('camunda-modeler-plugin-helpers').registerModdlePlugin;

var cartoucheModdle = require('./descriptors/cartouche.json');
registerModdlePlugin({cartouche : cartoucheModdle});
  • registerClientPlugin is the private function used in camunda-modeler-plugin-helpers to add a new object in the window.plugins array.

I hope this small contribution will be added to the new releases, please let me know any comment or improvement about it.

2 Likes