A criterion for extending morphisms from open subsets of smooth fibrations of algebraic varieties