1

I want to access a parameter of a method in an after plugin. The value of the parameter has been changed inside the original method, and I want to access the modified value. Example:

class vendorClass
{
    function paintBlue($room, $options)
    {
        // ...
        $options['color'] = 'light green';
    }
}

Now, my plugin looks like this:

class myPerfectMagentoPlugin
{
    public function __construct()
    {
    }

    public function afterPaintBlue($subject, $result, $room, $options)
    {
          // This $options array does not contain the color value:
          var_dump($options);
    }
}

How can I access the modified content of the $options variable in an after plugin?

2 Answers 2

3

There is no way to access that value in either an after or around plugin.

2

@shawn-abramson, right but if you do some changes at the original method then you can access the parameters of the change at around, after plugin.

If you pass this two-parameters ($room, $options) with a return of original function then you can data of both $room, $options at around and after plugin.

Original Method:

class vendorClass
{
    function paintBlue($room, $options)
    {
        // ...
        $options['color'] = 'light green'; 

        // Passing in array variable
        return [
            'room' => $room,
            'options'   => $options)
        ];
    }
}

After Plugin method:

class myPerfectMagentoPlugin
{
    public function __construct()
    {
    }

    public function afterPaintBlue($subject, $result, $room, $options)
    {
          $modifiedRoom =$result['room'];
          $modifiedOptions =$result['options'];
    }
}

Around Plugin Method

class myPerfectMagentoPlugin
{
    public function __construct()
    {
    }

    public function aroundPaintBlue($subject, \Callable $proceed, $room, $options)
    {
        // run original Method
        $result = $proceed($room, $options);    

        $modifiedRoom =$result['room'];
        $modifiedOptions =$result['options'];
    }
}
1
  • true - but if the original method is in the vendor folder, we might need a patch for this...
    – hey
    Jun 19, 2019 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.