Same as Visitor Gates for Palisades etc, Farmer Gates (equipped with ribbons or bells or whistles or whatever you deem necessary to put there) are an option when building a Stone Fence or Wooden Fence gates. They apply the same "invisible wall" mechanic to any domesticated and neither mounted nor leashed animal that try to enter or exit those gates.
Let's be honest, animal idiocy, dementia and retardation is off the charts this world. If you don't bother to build a 500x500 pasture for your herd, every time you open the fence gates, animals just start bouncing off the walls and each other and just plain and simple rush to leave the premises.
The "visitor gate" mechanic didn't really solve any problems while complicating things unnecessarily. Make at least some use of it, this proposed implementation would raise any herder's QoL greatly and save a lot, a LOT of frustration (and maybe even some cute, but stupid piglets that die in a bloody rampage of a repeatedly pathblocked farmer).