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

MessageTemplate - Add renderTemplate(). Deprecate renderMessageTemplate(). #21115

Merged
merged 1 commit into from
Aug 13, 2021

Conversation

totten
Copy link
Member

@totten totten commented Aug 13, 2021

Overview

This deprecates one recent/internal helper, CRM_Core_BAO_MessageTemplate::renderMessageTemplate(). As alternatives, use CRM_Core_BAO_MessageTemplate::renderTemplate() or CRM_Core_TokenSmarty::render().

Before

// Internal APIs
CRM_Core_BAO_MessageTemplate::sendTemplate(array $params): array;
CRM_Core_BAO_MessageTemplate::renderMessageTemplate(array $mailContent, bool $disableSmarty, $contactID,
                                                    array $smartyAssigns, array $tokenContext = []): array;

After

// Internal APIs
CRM_Core_BAO_MessageTemplate::sendTemplate(array $params): array;
CRM_Core_BAO_MessageTemplate::renderTemplate(array $params): array;
CRM_Core_TokenSmarty::render(array $messages, array $tokenContext, array $smartyContext): array;

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 in renderMessageTemplate merely juggle the names for smarty/disableSmarty and contactID/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 of sendTemplate(). This is a new function with broader scope, and it is better suited to generating preview-GUI. The renderTemplate($params) and sendTemplate($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.)

…plate() and TokenSmarty::render(). Add tests
@civibot
Copy link

civibot bot commented Aug 13, 2021

(Standard links)

@civibot civibot bot added the master label Aug 13, 2021
@eileenmcnaughton
Copy link
Contributor

@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

@totten
Copy link
Member Author

totten commented Aug 13, 2021

@eileenmcnaughton I don't mind posting the code change - but removal requires more work wrt r-run/QA. So I'll send that as a separate PR. (This part - adding renderTemplate() and deprecating renderMessageTemplate() - is safer/easier to QA.)

@eileenmcnaughton
Copy link
Contributor

@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);
Copy link
Contributor

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'

Copy link
Contributor

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

Copy link
Member Author

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.

@eileenmcnaughton
Copy link
Contributor

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

@eileenmcnaughton eileenmcnaughton merged commit c464c65 into civicrm:master Aug 13, 2021
@totten totten deleted the master-rendertpl branch August 13, 2021 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants