-
-
Notifications
You must be signed in to change notification settings - Fork 825
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
MessageTemplate - Add renderTemplate(). Deprecate renderMessageTemplate(). #21115
Conversation
…plate() and TokenSmarty::render(). Add tests
(Standard links)
|
@totten we should remove not deprecate that method - it is a recent method with explicit code comments saying not to call from outside of core |
@eileenmcnaughton I don't mind posting the code change - but removal requires more work wrt |
@totten OK - but note the only other place it's called from has solid enough test cover that I don't think r-run is actually required |
$mailContent = []; | ||
// sendTemplate has had an obscure feature - if you omit `toEmail`, then it merely renders. | ||
// At some point, we may want to invert the relation between renderTemplate/sendTemplate, but for now this is a smaller patch. | ||
[$sent, $mailContent['subject'], $mailContent['text'], $mailContent['html']] = static::sendTemplate($params); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hate this pattern of calling 'send' within 'render'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess what I would imagine is a shared function that this calls and send calls with the shared parts in it - having said that - this is hardly a new creation in this PR so not blocking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree that's a code-smell. Really, it's about the first half of sendTemplate()
which is shared (excl a few comments+defns). It might also make sense to flip the relationship (s.t. sendTemplate()
delegates to renderTemplate()
). For the moment, it is easier to juggle pending patches if sendTemplate()
's structure remains about the same. But we have (and will have) decent test coverage here, and I'd agree with rejiggering it in the not-distant-future.
The approach seems fine - I'm confident that the test cover on all code that calls the deprecated function is exhaustive so I haven't r-run |
Overview
This deprecates one recent/internal helper,
CRM_Core_BAO_MessageTemplate::renderMessageTemplate()
. As alternatives, useCRM_Core_BAO_MessageTemplate::renderTemplate()
orCRM_Core_TokenSmarty::render()
.Before
After
Use
CRM_Core_TokenSmarty::render()
if you want a low-level utility to render a template with the hybrid Token-Smarty template format. This function was recently extracted (#20870), so it is functionally the same. (The remaining bits inrenderMessageTemplate
merely juggle the names forsmarty/disableSmarty
andcontactID/contactId
).would be appropriate if you need to use the same notation (Token-Smarty) but with a different process (template-loading/validation/hooks).
Use
CRM_Core_BAO_MessageTemplate::renderTemplate()
if you want a high-level trial-run ofsendTemplate()
. This is a new function with broader scope, and it is better suited to generating preview-GUI. TherenderTemplate($params)
andsendTemplate($params)
use the same list of options+behaviors for template-loading, data-loading, data-validation, and hooks (Hook::alterMailContent
,Hook::alterMailParams
), etc. (This function is a pre-req for #20975.)