Video Lesson: Use a before plugin to modify function parameters in Magento

Use a before plugin to modify function parameters in Magento

This is premium content

Only available to enrolled or University students.
Join today to unlock all lessons in this course.

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...

Premium content

Enroll to unlock the full content and all course materials.

Maggie

Hey, I'm Maggie! 👋

Ask me anything.

Want to chat with Maggie?

Enroll in this course for AI tutor access.

Comments

Join the discussion!

Comments

Want to comment on this lesson?

Enroll in this course to leave comments.