Use a before plugin to modify function parameters in Magento
Learn how to use a Magento 2 before plugin to modify observer execute parameters and add custom request data.
Lesson Content
Let’s take a look at this LogPostDetailView observer class from the Macademy_Blog module, and let’s say we wanted to manually add a parameter to the request object with some backend code. Since the request parameter is passed as an extra data parameter to the $observer argument, we can easily change the value of this $observer variable with a before plugin.
All plugins will go within a Plugin directory, so create a directory within your module named Plugin. Just like observers, name plugins after what they do. Since we’d like to add data to the request object of the post detail...
Join the discussion!
Comments
Want to comment on this lesson?
Enroll in this course to leave comments.