Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pimcore Mail does not provide mail params in view model #5785

Closed
podarcis opened this issue Feb 12, 2020 · 4 comments · Fixed by #5847
Closed

Pimcore Mail does not provide mail params in view model #5785

podarcis opened this issue Feb 12, 2020 · 4 comments · Fixed by #5847
Assignees
Labels

Comments

@podarcis
Copy link
Contributor

@podarcis podarcis commented Feb 12, 2020

Bug Report

The documentation https://pimcore.com/docs/6.x/Development_Documentation/Development_Tools_and_Details/Email_Framework/Pimcore_Mail.html states that setParams sets the parameters for both placeholders and the email view. However, the view can not access these parameters as they aren't set

Expected behavior

Mail param foo can be accessed in template by using $this->foo.

AFAICR that was the behavior in Pimcore 4.

Actual behavior

View model does not contain key foo and thus cannot be accessed from within template (in this case PHP template).

However, the params are accessible through request's attributes ($request->attributes) from e.g. within controller action.

Steps to reproduce

  1. Prepare and send a mail with \Pimcore\Mail using params and a document:
$mail = new \Pimcore\Mail();
$mail->addTo('example@pimcore.org');
$mail->setDocument('/email/myemaildocument');
$mail->setParams(['foo' => 'bar');
$mail->send();
  1. Create email document /email/myemaildocument and set FooController and fooAction.
  2. Have FooController and fooAction render a template foo.html.php.
  3. Template foo.html.php tries to access $this->foo, but its unset and thus null.

Crude workaround

Set some/all request's attribute keys as view model variables.

    public function onKernelController(FilterControllerEvent $event)
    {
        parent::onKernelController($event);

        // set params for view
        $request = $this->requestHelper->getCurrentRequest();
        $viewParams = $request->attributes->all();
        foreach ($viewParams as $key => $value) {
            $this->view->$key = $value;
        }
    }

Using Pimcore 6.4.2

@dpfaffenbauer

This comment has been minimized.

Copy link
Contributor

@dpfaffenbauer dpfaffenbauer commented Feb 12, 2020

that is actually on purpose, since how should attributes be passed on the template when the controller is responsible to render the template?

@podarcis

This comment has been minimized.

Copy link
Contributor Author

@podarcis podarcis commented Feb 12, 2020

@dpfaffenbauer Thanks for your reply. I'm just noting that either the documentation is outdated and/or the behavior differs from Pimcore 4, or am I wrong? I have no problem extracting the params from attributes manually and provide these to the view model if that's the way it's intended.

@dpfaffenbauer

This comment has been minimized.

Copy link
Contributor

@dpfaffenbauer dpfaffenbauer commented Feb 12, 2020

It does differ from Pimcore 4, but that should be clear, since there was quite a major change in between ;)

Yes, extract that in your action and pass it on to the view

@brusch

This comment has been minimized.

Copy link
Member

@brusch brusch commented Feb 17, 2020

Docs need to be updated.
Thanks for reporting!

@brusch brusch added the Task label Feb 17, 2020
@brusch brusch added this to To do in #79 | 17/02/2020 - 28/02/2020 via automation Feb 17, 2020
dvesh3 added a commit that referenced this issue Feb 18, 2020
dvesh3 added a commit that referenced this issue Feb 18, 2020
@dvesh3 dvesh3 moved this from To do to In progress in #79 | 17/02/2020 - 28/02/2020 Feb 18, 2020
dvesh3 added a commit that referenced this issue Feb 19, 2020
@brusch brusch closed this in #5847 Feb 19, 2020
#79 | 17/02/2020 - 28/02/2020 automation moved this from In progress to Done Feb 19, 2020
brusch pushed a commit that referenced this issue Feb 19, 2020
* [Mail] Update docs #5785

* [Mail] Update docs - adapt warnings #5785
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

4 participants
You can’t perform that action at this time.