Skip to content

dev/core#6308 FormBuilder - allow tokens and html markup in label, help_pre, help_post and rich content - #35562

Merged
colemanw merged 13 commits into
civicrm:masterfrom
ufundo:afform-tokens-in-copy
May 13, 2026
Merged

dev/core#6308 FormBuilder - allow tokens and html markup in label, help_pre, help_post and rich content#35562
colemanw merged 13 commits into
civicrm:masterfrom
ufundo:afform-tokens-in-copy

Conversation

@ufundo

@ufundo ufundo commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Overview

Adds <af-markup> and <af-token> elements to which allow for generic rendering of markup with tokens inside an afform -- including markup coming from angular expressions like {{ $ctrl.defn.label }}.

Before

  • label, help_pre, help_post can only be plain text

After

  • new civi-rich-text-input - similar to CRM.wysiwyg.createCollapsed but usable in angular context; and supports a token picker
  • label, help_pre, help_post include html markup and or tokens with afform values
  • rich content areas can include tokens

Technical Details

The use of the custom elements may seem a bit roundabout, but it seems to me a good way to handle the joint challenge of rendering html provided by the form admin without rendering any html that a form user might try to sneak in via token values.

It also lends itself nicely to onward development of generic expression evaluation / math; and avoids entrenching angular dependency.

Comments

Having the token pickers on all these fields feels a bit much. It would be good if we could tuck them away somehow.

@civibot

civibot Bot commented Apr 30, 2026

Copy link
Copy Markdown

🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷

Introduction for new contributors...
  • If this is your first PR, an admin will greenlight automated testing with the command ok to test or add to whitelist.
  • A series of tests will automatically run. You can see the results at the bottom of this page (if there are any problems, it will include a link to see what went wrong).
  • A demo site will be built where anyone can try out a version of CiviCRM that includes your changes.
  • If this process needs to be repeated, an admin will issue the command test this please to rerun tests and build a new demo site.
  • Before this PR can be merged, it needs to be reviewed. Please keep in mind that reviewers are volunteers, and their response time can vary from a few hours to a few weeks depending on their availability and their knowledge of this particular part of CiviCRM.
  • A great way to speed up this process is to "trade reviews" with someone - find an open PR that you feel able to review, and leave a comment like "I'm reviewing this now, could you please review mine?" (include a link to yours). You don't have to wait for a response to get started (and you don't have to stop at one!) the more you review, the faster this process goes for everyone 😄
  • To ensure that you are credited properly in the final release notes, please add yourself to contributor-key.yml
  • For more information about contributing, see CONTRIBUTING.md.
Quick links for reviewers...

➡️ Online demo of this PR 🔗

@civibot civibot Bot added the master label Apr 30, 2026
@civibot

civibot Bot commented Apr 30, 2026

Copy link
Copy Markdown

The issue associated with the Pull Request can be viewed at https://lab.civicrm.org/dev/core/-/issues/6308

@ufundo

ufundo commented Apr 30, 2026

Copy link
Copy Markdown
Contributor Author

Having the token pickers on all these fields feels a bit much. It would be good if we could tuck them away somehow.

Or could we have one token picker somewhere in a corner of the screen, that could be used for any of the fields that allow tokens?

@ufundo ufundo changed the title dev/core#6308 allow tokens and html markup in FormBuilder label, help_pre, help_post dev/core#6308 FormBuilder - allow tokens and html markup in label, help_pre, help_post Apr 30, 2026
Comment thread ext/afform/core/ang/af/afMarkup.element.js
@ufundo
ufundo marked this pull request as ready for review April 30, 2026 14:50
@ufundo

ufundo commented Apr 30, 2026

Copy link
Copy Markdown
Contributor Author

@colemanw for WYSIWYG editor question - do you think it's reasonable to leave for a separate PR?

I appreciate it's a slightly awkward middle ground when markup is supported, but you have to enter it manually. But it feels quite distinct implementation-wise; and I'd rather confirm/get this merged before starting out on the WYSIWYG side.

@mattwire

mattwire commented May 1, 2026

Copy link
Copy Markdown
Contributor

@ufundo a screenshot would probably be helpful here to understand what we should be seeing when testing this?

@ufundo
ufundo force-pushed the afform-tokens-in-copy branch 2 times, most recently from a783e38 to 127d15f Compare May 12, 2026 08:46
@ufundo ufundo changed the title dev/core#6308 FormBuilder - allow tokens and html markup in label, help_pre, help_post dev/core#6308 FormBuilder - allow tokens and html markup in label, help_pre, help_post and rich content May 12, 2026
@ufundo
ufundo force-pushed the afform-tokens-in-copy branch from 127d15f to 61bcae8 Compare May 12, 2026 09:41
@ufundo

ufundo commented May 12, 2026

Copy link
Copy Markdown
Contributor Author

@colemanw I've added the wysiwyg editing now. The interplay between angular, CRM.wysiwyg and token picking was... painful. But I think it's a good solution. The civi-rich-text-input should be able to replace CRM.wysiwyg.createCollapsed on the quickform forms as well, but it's a little bit of work.

@mattwire here's before:

no tokens in Rich content blocks; weird bug if you click Cancel rather than Done

Screencast.from.2026-05-12.10-02-09.mp4

raw html editing in the confirmation message

Screencast.from.2026-05-12.10-04-33.mp4

no html in help_pre / help_post

Screencast.from.2026-05-12.10-03-50.mp4

After:

Screencast.from.2026-05-12.10-08-17.mp4

(fixed the undefined thing in the confirmation message)

@ufundo

ufundo commented May 12, 2026

Copy link
Copy Markdown
Contributor Author

The civi-rich-text-input should be able to replace CRM.wysiwyg.createCollapsed on the quickform forms as well, but it's a little bit of work

Done with b6bba19 and 6328ca4

@ufundo
ufundo force-pushed the afform-tokens-in-copy branch from b6bba19 to f24f3ed Compare May 12, 2026 10:30
}

get afFormCtrl() {
return angular.element(this.afForm).controller('afForm');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kindof amazing that this even works, but I'm glad it does!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep.

One day when the af-form is a WebComponent it can just become this.closest('af-form').getTokens() etc. But until then this seems to work pretty well for interfacing / piecewise conversion.

Comment thread js/wysiwyg/crm.wysiwyg.js
Comment on lines +125 to +133
if (this.closest('af-gui-editor')) {
const afGuiEditor = angular.element(this.closest('af-gui-editor')).controller('afGuiEditor');
return {
results: afGuiEditor.getTokens(this.hasAttribute('include-submission-tokens'))
};
}
else {
throw new Error('civi-rich-text-input[token-picker] doesn\'t know how to get available tokens outside of af-gui-editor context yet');
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This coupling is far from ideal as I'm sure you know. But it gets the job done for now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes...

I think it would probably be better to pass the token list through to the component as a JSON attribute, something like

afGuiField.html:

...
<civi-rich-text-input token-list="{{ $ctrl.getTokensJson() }}" >
...

I was worried this might be inefficient given a) it's a dynamic list based on what fields are currently placed on the form; b) there will likely be multiple civi-rich-text-inputs. But it may still be better to reduce the coupling.

override for special context af-gui-container
@ufundo
ufundo force-pushed the afform-tokens-in-copy branch from 6328ca4 to 719a0fe Compare May 12, 2026 14:04
@ufundo

ufundo commented May 12, 2026

Copy link
Copy Markdown
Contributor Author

@colemanw let me know if it helps to break out some of the constituent parts of this PR as it has become a bit of a monster now.

I think if breaking it up I would reverse the order:

  • add civi-rich-text-input for the quickform places first
  • then switch in for the existing FormBuilder rich text inputs
  • then add for help_pre and help_post
  • then add the token picker / token support

@colemanw

Copy link
Copy Markdown
Member

@ufundo I think it's fine to merge & iterate on this. Thanks for all your work on it.

@colemanw
colemanw merged commit f9aa997 into civicrm:master May 13, 2026
1 check passed
@colemanw

colemanw commented Aug 7, 2026

Copy link
Copy Markdown
Member

Commit 575232f caused a regression. See #36439

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants