Spain moves closer to legalizing gay marriage