The essential thing for making the interference pattern is that the electron can reach a point on the screen in two ways (in this case) where each way picks up a phase that destructively interferes with the other, crucially neither of the paths can cause any other asymmetrical contribution to the overall phase - this means the two paths can't interact permanently with the environment.
Now, the non-intuitive thing about quantum particles is that they don't necessarily go in straight lines - in this case the electron paths that do meet up to interfere, could have passed through both slits without interacting with any slit material on the sides. It doesn't matter for the dark peaks that other electron paths collide with the slits or external environment far away (in fact some will, and in those cases you lose the high-peak visibility on the screen as you lose some electrons you should have detected otherwise).
If you add a "detector" in one of the slits (or, as in your question, you let photons interact with the paths), the electron path's interaction with the detector will to some degree change the phase of that path permanently, which means the dark peaks will lose some of the possible destructive interference (the ref. Roger Vadim linked shows a paper where they did just this). Incidentally an interesting aspect of these detectors-in-the-slits setups is that if the detectors are not perfect, i.e. they will misfire, you get back some of the lost destructive interference, as the overall phase is restored in the cases where one detector fires correctly and the other misfires at the same time!
This discussion is idealized - of course there will be paths where the electron do interact with the sides of the slits and reflect and add a momentum that could (theoretically) be measured, etc... all these other paths contribute to reducing the fidelity of the interference.