How to define asset upload path


I’m attempting to change the default upload path when adding an image to a Document, based on the path of the Document. I’m trying to understand the code under “Asset Upload Path” on this page:, but I’m not sure where I would stick that code? I’ve played with listeners using the service.yml file, but haven’t tried dynamically adding listeners.