• totten's avatar
    CiviMail - Restore support for previewing action-tokens via TokenProcessor/Flexmailer · e026b9e4
    totten authored
    Overview
    --------
    
    When using `TokenProcessor` to generate a mailing (e.g.  as with Flexmailer/Mosaico), the action-tokens (e.g.
    `{action.optOutUrl}`) are generated via `CRM_Mailing_ActionTokens`.  To properly generate them,
    `CRM_Mailing_ActionTokens` relies on certain information (e.g.  mailing/job ID).  However, that information is no
    longer available when performing a "Preview" -- leading to misbehavior in previews.  This patch allows Flexmailer to
    restore parity for previewing those tokens.
    
    Before (Pre-5.6)
    ----------------
    
    * When a user begins composing a mailing, CiviMail creates a draft mailing with a concrete ID (e.g.  `mailing #123`).
    * To preview the mailing, the UI calls `Mailing.preview` API with the ID of the mailing.
    * Flexmailer/Mosaico generates the preview by calling `TokenProcessor` and therefore `CRM_Mailing_ActionTokens`.
    * `CRM_Mailing_ActionTokens` has strictness checks. These pass because the ID is available.
    
    Before (5.6-5.12)
    ----------------
    
    As a performance enhancement, CiviCRM 5.6 (PR #12509; [mail#20](mail#20)) revised
    the signature for `Mailing.preview` API to allow previews *without* having a specific mailing record/job/ID. Consequently:
    
    * When a user begins composing a mailing, CiviMail creates a draft mailing with a concrete ID (e.g.  `mailing #123`).
    * To preview the mailing, the UI calls `Mailing.preview` API ~~with~~ **without** the ID of the mailing.
    * Flexmailer/Mosaico generates the preview by calling `TokenProcessor` and therefore `CRM_Mailing_ActionTokens`.
    * `CRM_Mailing_ActionTokens` has strictness checks. These ~~pass~~ **fail** because the ID is ~~available~~ **unavailable**.
    
    After
    ----------------
    
    * When a user begins composing a mailing, CiviMail creates a draft mailing with a concrete ID (e.g.  `mailing #123`).
    * To preview the mailing, the UI calls `Mailing.preview` API ~~with~~ **without** the ID of the mailing.
    * Flexmailer/Mosaico generates the preview by calling `TokenProcessor` and therefore `CRM_Mailing_ActionTokens`.
    * `CRM_Mailing_ActionTokens` has ~~strictness~~ **less strict** checks. These **pass** because the `context[schema]` hints that
      a mailing ID *will be available* when needed.
    e026b9e4
ActionTokens.php 4.9 KB