CRAFTERCMS-818
Added code to protect against falling into infinite loop when having circular dependencies
Merge pull request #220 from dejan-brkic/2.2.x

CRAFTERCMS-818