How to attach a doorbell transformer to a plastic junction box?
As I Understand It:


To do it wrong, you simply drill a hole in the box, which is
presumably what was done.
To do it right you need a box with a knockout for a hole, which will
normally be a steel box.