Planck intermediate results. XXXV. Probing the role of the magnetic field in the formation of structure in molecular clouds