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

CRAFTERCMS-818