An implicit wetting–drying algorithm for the discontinuous Galerkin method