Context. Protoplanetary disks are known to form around nascent stars from their parent molecular cloud as a result of angular momentum conservation. As they progressively evolve and dissipate, they also form planets. While a lot of modeling efforts have been dedicated to their formation, the question of their secular evolution, from the so-called class 0 embedded phase to the class II phase where disks are believed to be isolated, remains poorly understood. Aims. We aim to explore the evolution between the embedded stages and the class II stage. We focus on the magnetic field evolution and the long-term interaction between the disk and the envelope. Methods. We used the GPU accelerated code IDEFIX to perform a 3D, barotropic, non ideal magnetohydrodynamic (MHD) secular core collapse simulation that covers the system evolution from the collapse of the pre-stellar core until 100 kyr after the first hydrostatic core formation and the disk settling while ensuring sufficient vertical and azimuthal resolutions (down to 10−2 au) to properly resolve the disk internal dynamics and non axisymmetric perturbations. Results. The disk evolution leads to a power-law gas surface density in Keplerian rotation that extends up to a few 10 au. The magnetic flux trapped in the disk during the initial collapse decreases from 100 mG at disk formation down to 1 mG by the end of the simulation. After the formation of the first hydrostatic core, the system evolves in three phases. A first phase with a small (∼10 au), unstable, strongly accreting (∼ 10−5 M⊙ yr−1) disk that loses magnetic flux over the first 15 kyr, a second phase where the magnetic flux is advected with a smooth, expanding disk fed by the angular momentum of the infalling material, and a final phase with a gravitationally regulated ∼60 au disk accreting at at few 10−7 M⊙ yr−1. The initial isotropic envelope eventually feeds large-scale vertically extended accretion streamers, with accretion rates similar to that onto the protostar (∼ 10−6 M⊙ yr−1). Some of the streamer material collides with the disk’s outer edge and produces accretion shocks, but a significant fraction of the material lands on the disk surface without producing any noticeable discontinuity. Conclusions. While the initial disk size and magnetization are set by magnetic braking, self-gravity eventually drives accretion, so that the disk ends up in a gravitationally regulated state. This evolution from magnetic braking to self-gravity is due to the weak coupling between the gas and the magnetic field once the disk has settled. The weak magnetic field at the end of the class I phase (Bz ∼ 1 mG) is a result of the magnetic flux dilution in the disk as it expands from its initial relatively small size. This expansion should not be interpreted as a viscous expansion, as it is driven by newly accreted material from large-scale streamers with large specific angular momentum.