Magnetic field evolution during prominence eruptions and two-ribbon flares