-
-
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
Afform - Support embedding forms via WP shortcodes. #19687
Conversation
(Standard links)
|
@colemanw As per my message on Mattermost... the We can easily make an exception for Afform where the If Afform is independent of |
Per discussion with @christianwach I've fixed the initial limitations. |
3242aad
to
b6fc3dc
Compare
This allows civi core or extensions to supply content for shortcodes without rendering a page; they can simply implement `civicrm_shortcode_get_data` and return the content. Previously this filter was only invoked when multiple shortcodes were present, now it is invoked in all cases if the shortcode attributes do not provide a `q` callback path. See civicrm/civicrm-core#19687
b6fc3dc
to
0098547
Compare
0098547
to
2674ad0
Compare
Quick work @colemanw - we discussed this as a good idea 2 days AFTER you left the meeting & now magically there is a PR. |
2674ad0
to
372e0dd
Compare
This allows civi core or extensions to supply content for shortcodes without rendering a page; they can simply implement `civicrm_shortcode_alter_conent` and return the content. This new filter is called whenever displaying contents of a single shortcode and will allow any shortcode contents to be displayed or modified. See civicrm/civicrm-core#19687
Yes, I think this should be done independent of I have to admit that some of the scenarios around routes<=>short-codes make my head hurt, so I don't claim to fully understand them. However, I'm a little concerned this is integrating from the wrong angle. So bear with me while I try to verbalize my understanding of a current situation -- and describe then how this is a problem. Context: Civi Pages<=> WP Shortcodes: I understand the difficulty in Civi-WP short-codes to be the consequence of impedance mismatch. Civi-WP maps between two things (a "page"/"route"/"menu-item" in Civi and a "shortcode" in WP). These are similar in that both output a blob of HTML. The difference:
To expose standalone pages as mixable shortcodes, the Civi-WP short-code integration has fiddly-bits like "hijack"ing. Context: Civi Pages<=>Afforms: For Afform, we had a similar problem, but going in the other direction:
To expose mixable afforms as standalone pages, the afform extension has fiddly-bits like "afformStandalone" (which sets up a standalone page and then loads a single afform into it). For // AfformBase.php
$loader->setModules([$afform['module_name'], 'afformStandalone']);
...
$loader->getRes()->addSetting([
'afform' => [
'open' => $afform['directive_name'],
],
]); <!-- AfformBase.tpl -->
<div ng-app="afformStandalone">...</div> // AfformStandalone.js
template: function() {
return '<div id="bootstrap-theme"><' + CRM.afform.open + '></' + CRM.afform.open + '></div>';
} Issue (Lower-level/symptomatic POV): If a page includes two short-codes which reference different afforms, then Issue (Higher-level POV): It looks like this PR forms a bridge along this 3-part path: Mixable Afform =(1)=> Standalone Civi page =(2)=> Mixable Shortcode This raises a few mismatches:
Alternative (sketch): My gut says:
|
The code looks like it is heading in the right direction and I agree with @totten's thoughts here I think. |
@totten Sounds like you've got a pretty good handle on them to me :) |
372e0dd
to
2fc76eb
Compare
This allows civi core or extensions to supply content for shortcodes without rendering a page; they can simply implement `civicrm_shortcode_get_content` and return the content. This new filter is called whenever displaying contents of a pathless shortcode. See civicrm/civicrm-core#19687
I've rebased this to reflect the feedback from @christianwach and @totten - it now works the way Tim described, independently of Civi page routing, and consequently it's not restricted to one shortcode per page. Note this depends on civicrm/civicrm-wordpress#244 |
2fc76eb
to
fc91893
Compare
Nice - it would be REALLY good to get this merged before we cut the rc |
Adds a v3 Afform api solely for the purpose of enabling entityRef widgets, which use APIv3.
This implements the necessary hooks & callbacks for picking an afform from the Civi shortcode popup, and displaying the afform when viewing a single WP post/page or list of posts. Note that unlike traditional Civi shortcodes, afform does not rely on invoking a civi page request, but simply outputs the AngularJS directive.
fc91893
to
f228ad7
Compare
commenting at civicrm/civicrm-wordpress#244 |
Per discussion on the other - ok to merge now to be in the rc but any changes based on further feedback can also go into the rc |
Documentation PR, https://lab.civicrm.org/documentation/docs/sysadmin/-/merge_requests/325 |
Is there a way to use these shortcodes on things like the Petition Thank You page? When I enter a shortcode to displpay a SearchKit form, I get an error "This Shortcode could not be handled. It could be malformed or used incorrectly." |
Overview
This adds support for Afform shortcodes. It allows any Custom Form or Search Form to be embedded in a WP page or post.
Technical Details
There were 2 technical challenges that have been fixed for this PR:
In order for the EntityRef widget to fully work, a v3 API needed to be added for Afform, and APIv3 needed improvements to the
_civicrm_api3_basic_array_get
function to accept more operators than just=
. Fixed via APIv3 - Improve array-based apis to support sorting and operators #19690Civi's shortcode handling needed to be updated so that content could be loaded via callback instead of running a server route. Fixed via Allow shortcodes to be rendered without invoking Civi page civicrm-wordpress#244