CRM-8526 Support [contribution.custom_nn] tokens in templates

    Details

    • Versioning Impact:
      Patch (backwards-compatible bug fixes)
    • Documentation Required?:
      Developer Doc
    • Funding Source:
      Needs Funding

      Description

      Add support for processing of tokens for contribution custom fields.

      The attached patch provides working beta code for this functionality. It includes changes to support processing of tokens in the form

      {contribution.custom_44}

      in templates.

      To Do's:
      Provide tests.
      Add support contribution tokens in reminder messages.
      Add support for inserting tokens in templates using the drop-down.
      Add support for custom field tokens for other components, eg membership, events, etc.
      Limit in the UI the ability to insert custom field tokens to the components associated with that template (ie make templates aware of which components they support).

      Next steps: feedback from core team on what is required for this to be included in a release. Preference: just tests, and any fixes required.

        Attachments

        1. contributiontokens.txt
          2 kB
          Richard
        2. patch.CRM-8526.txt
          18 kB
          Joe Murray

          Activity

          [CRM-8526] Support [contribution.custom_nn] tokens in templates
          Donald A. Lobo added a comment -

          1. Dont see a patch attached

          2. How does it deal with a contact having multiple contributions. Which contribution;s custom field is taken?

          Joe Murray added a comment -

          this patch is against 3.4.2.

          Joe Murray added a comment -

          1. patch added now
          2. This is intended to support generating pdfs or emails from component search results, such as emails on contribution search results. The entity_id, in this case contributionID, is found in the $params object being used for the generation of content from a template.

          Donald A. Lobo added a comment -

          hey joe:

          a couple of things:

          1. Can you regen this patch against 4.1, since we've improved the token support there

          2. Can you add tests

          3. Not sure why u renamed: replaceComponentTokens to replaceContributionTokens rather than having both those functions co-exists. I have not checked the code to see if replaceComponentTokens is even called

          If you can get a patch in the next 2 weeks that would be great and potentially allow us to add it to 4.1. If not, we'll defer this to 4.2 and integrate when above is done

          Donald A. Lobo added a comment -


          Closing issues in batch on 4/16/13 since these issues have not been worked on in a long long time

          David Glick added a comment - - edited

          Can this be reopened? I can't find any way currently to include a custom contribution field in a thank you letter.

          {contribution.custom_XX}

          doesn't work (because the custom values are not loaded in getContributionTokenDetails) and the tokenValues hook is not called for the contribution tokens.

          Joe Murray added a comment -

          Before we reopen, could you try

          {contribution.custom_XX}

          (no $).

          David Glick added a comment -

          Yeah,

          {contribution.custom_XX}

          is what I tried. The $ was a typo when I entered my comment here, and I've edited it to fix.

          Joe Murray added a comment -

          Edsel, can you try to reproduce David's issue and document results here. Thanks.

          Joe Murray added a comment -

          Looking more carefully at the issue comments it seems that the patch was never committed to core, David Glick. I don't think we have the resources to rework the old 3.4 code from 2011 without sponsorship, unfortunately. It would be great if you could more this functionality forward, possibly based on that old code.

          Allen Shaw added a comment -

          Monish Deb or Yashodha Chaku Looks like this PR has been merged. Should we update the Fix Version here?

          Monish Deb added a comment -

          Allen Shaw Can we close this issue?

          Joe Murray added a comment -

          I think it would be good to update developer documentation on how to use this before closing issue.

          Allen Shaw added a comment -

          Joe Murray Did you assign this to me?

          Joe Murray added a comment -

          Yes, since Monish wanted you to take next step in determining if issue can be closed. Not sure who should update the documentation. Or even decide if issue should be closed.

          Allen Shaw added a comment -

          I see; thanks for explaining Joe Murray.

          Monish Deb, I haven't done any testing on this so can't confirm the fix and can't suggest whether to close or not. I was just suggesting to update the Fix Version because the PR was merged. Perhaps Joe as the OP could comment on whether it's fixed – and he does make a good point about documentation.

          Joe Murray added a comment -

          Edsel, please test, close issue if all is working, and fix documentation at https://wiki.civicrm.org/confluence/display/CRMDOC/Tokens regarding places where this token can be used. Also, please fix documentation for contact.custom_nn fields re: whether they work in templates etc at same time, please. Thanks!

          Joe Murray added a comment - - edited

          So I see this was worked on as part of a larger project addressing CRM-19786, CRM-18141, CRM-19757. This issue was not closed, but the PR was merged. I have a report that this functionality is not working. Will assign for testing and fixes this month. If it was not included, we can just close as Not fixed. If it was included, let's make sure that these tokens are available when mailing from Find Contributions search results, and also if the code is there but just not working properly, for scheduled reminder mailings for contributions, memberships (if that makes sense - seems dicey to handle all the edge cases), and participants (again, partial payments may make this undoable at moment).

          Joe Murray added a comment - - edited

          Jitendra Purohit I see this issue was assigned to you until Monish assigned to Allen asking if it could be closed. Could you test functionality. If it is working, please assign to Edsel to review the documentation. If it was not included in the merged PR, then close and mark as Won't Fix. If it is broken, could you work on this as though it is a reversion bug, introduced in a recent version? Thanks!

          Peter Davis is Jitendra still doing core work or has he shifted to you?

          Edsel Lopez added a comment - - edited

          Joe Murray I have tested this by sending a scheduled reminder to myself after creating a contribution with a multi-valued custom field and few single valued fields of various HTML types. It works as expected for scheduled reminders for contributions. It does not work while sending an email from contribution search results though, which I think is acceptable since the context is more inclined towards contact tokens rather than contribution tokens, with the latter not being available as possible selections.

          It also does not work for participants and memberships. I tested this by editing the contribution after creating the registration/membership and adding the custom fields and then trying to send myself a scheduled reminder. Not sure if this is expected behavior since the token list allows one to select a variety of contribution related tokens, none of which seem to work. I tried adding tokens for contribution ID and total amount and they showed up blank too.

          Richard added a comment - - edited

          I can confirm [contribution.custom_nn] tokens now work in scheduled contribution emails.

          Unfortunately I can also confirm most other (regular) contribution tokens do not work.
          There are some available from the token drop-down list but they do not work.

          Some observations:
          Tokens that work are:

          {contribution.id} / {contribution.payment_instrument} / {contribution.net_amount} and {contribution.invoice_id}

          But very basic ones (which we need most) do NOT work like: {contribution.contribution_status_id}
          and {contribution.receipt_date}

          Some other quirks (wrong token is inserted):
          The Contribution ID is inserted using the drop-down as: {contribution.contribution_id}, but like that it doesn't work. Instead {contribution.id}

          is the one that works. Likewise

          {contribution.contribution_source}

          does not work, but

          {contribution.source}

          does. Same for

          {contribution.financial_type}

          (does not work) but

          {contribution.type}

          does. (https://issues.civicrm.org/jira/browse/CRM-19729)

          {contribution.status}

          does work and gives the contribution status label.
          But like states contribution_status_id does not work for the status id.

          I have no ability to solve this, but tracking this down is the most valuable thing I can contribute

          Edsel Lopez added a comment -

          Thanks for testing this Richard!
          I will test and provide a fix.

          Edsel Lopez added a comment - - edited

          Hi Richard

          I managed to do some testing and could not replicate the issue you were having. For clarity sake, I have copied your last comment as body for the email and mailed myself details of a test contribution I made.

          Here is the email:

          <p>Tokens that work are:</p>

          <p>1 / Check / $ 787.00 and <br /> 123445
          <br />
          But very basic ones (which we need most) do NOT work like: 1<br />
          and 2017-03-30 01:20:00<br />
          <br />
          Some other quirks (wrong token is inserted):<br />
          The Contribution ID is inserted using the drop-down as: 1, but like that it doesn't work. Instead 1</p>

          <p>is the one that works. Likewise</p>

          <p>source test</p>

          <p>does not work, but</p>

          <p></p>

          <p>does. Same for</p>

          <p>Donation</p>

          <p>(does not work) but</p>

          <p></p>

          So it looks like

          {contribution.source}

          ,

          {contribution.type}

          and

          {contribution.status}

          are the ones not working, but handled in the tokens out of the box as per the dropdown. I would suggest you have a look at if any custom extensions are at play here, specially one's that invoke the tokenValues hook.

          Richard added a comment -

          Attached is a the code for a table with 'official' tokens as provided by te dropdown from within the scheduled reminder section. Tokens that do not work unless with a different syntax are:

          • Contribution ID (needs: [contribution.id] instead of [contribution.contribution_id]
          • Contribution Status (needs: [contribution.status] instead of [contribution.contribution_status_id]
          • Contribution Source (needs: [contribution.source] instead of [contribution.contribution_source]
          • Financial Type (needs: [contribution.type] instead of [contribution.financial_type]

          The good news: Our custom contribution field does work! Still for smarty purposes I would really also be able to retrieve the contribution status ID (apart from the status label). Smarty does not work very well with labels with spaces in them.

          So summarized: some tokens are working (net amount, invoice ID, receipt date) but others do not work with the inserted token code, but do work with a different token syntax.

          Joe Murray added a comment -

          Let's close this issue regarding custom_nn tokens and open a different one for the discussion of core contribution tokens. Richard, can you try to replicate on dmaster, and assign new issue to Edsel if you replicate?

          Joe Murray added a comment -

          The currently reported errors are not to do with custom contribution tokens.

            People

            • Assignee:
              Edsel Lopez
              Reporter:
              Joe Murray

              Dates

              • Created:
                Updated:
                Resolved: