Restriction / rules for bpmn symbol

Did you follow the way on how to load the custom rule modules like in the example? So that you move your rule inside a seperate directory and load your custom rules via an index.js.

So given following structure:

rules/
-- Rules.js
-- index.js
app.js

rules/CustomRules.js

import inherits from 'inherits';
import RuleProvider from 'diagram-js/lib/features/rules/RuleProvider';

export default function CustomRules(eventBus) {
  RuleProvider.call(this, eventBus);
}

inherits(CustomRules, RuleProvider);
CustomRules.$inject = [ 'eventBus' ];

CustomRules.prototype.init = function() {
  this.addRule('connection.create', 1100, function(context) {
    var source = context.source,
        target = context.target;

    if (source.type === 'bpmn:StartEvent' && target.type === 'bpmn:EndEvent') {return false;}
  });
};

rules/index.js

import CustomRules from './CustomRules';

export default {
  __init__: [ 'customRules' ],
  customRules: [ 'type', CustomRules ]
};

And then load your modeler (app.js)

import customRuleModules from './rules';

this.modeler = new BpmnModeler({
  container: ‘#bpmnview’,
  keyboard: {
   bindTo: window
  },
 additionalModules: [
   customRulesModules
 ]
});

This example works for me. Please share if it doesn’t on your case, so it will likely caused by something different in your application.

1 Like