There are definitely recipes that use whole cloves or shallots in them. However, slicing them gives you more surface area which will also impart more flavor. Plus, if your garlic and onion are already prepped and sliced, it means you can include them in your dishes along with a spoon of oil.