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

dev/core#5603 Support multi-record CustomGroups for Events using Afform tab display #31606

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

ufundo
Copy link
Contributor

@ufundo ufundo commented Dec 16, 2024

Overview

Currently only Contacts can have CustomGroups with is_multiple = TRUE. This adds support for creating is_multiple custom groups for Events. These are then displayed as an additional tab in the Manage Events tabset.

Before

  • only Contacts can have multi-record custom groups

After

  • Events can have multi-record custom groups
  • (with AdminUI extension enabled + CustomGroup style set to "Tab with table") these are displayed using an additional in the Manage Events section

Technical Details

This involves trying to generalise some of the plumbing for AfformTabs - essentially changing hard-coded contact_id to entity_id. In the process I've removed AfformTab.tpl and AfformBlock.tpl (the latter change isn't strictly necessary, but feels good step to pave the way for further afform-based functionality for non-Contact entities.

Comments

  • need to check AfformBlock changes in contact summary editor hook
  • at the moment effectively requires AdminUI + style = "Tab with table" for these custom groups (otherwise they won't be exposed anywhere in the UI)

Copy link

civibot bot commented Dec 16, 2024

🤖 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 Dec 16, 2024
@ufundo ufundo changed the title Support multi-record CustomGroups for Events using Afform tab display dev/core#5603 Support multi-record CustomGroups for Events using Afform tab display Dec 16, 2024
@colemanw
Copy link
Member

@ufundo is the switch from contact_id to entity_id going to affect existing user-created afforms?

@ufundo
Copy link
Contributor Author

ufundo commented Dec 16, 2024

@ufundo is the switch from contact_id to entity_id going to affect existing user-created afforms?

It shouldn't do. I passed entity_id and contact_id in the assign here https://github.com/civicrm/civicrm-core/pull/31606/files#r1887316810 , so either should work (and the other will be ignored if not used).

I r-ran as follows:

  • start on master
  • making local edits the the Membership tab afform
  • save to create a local copy with a hard reference to options.contact_id
  • check out this branch
  • my locally edited version of membership tab afform still works

@colemanw
Copy link
Member

It shouldn't do

Ok, and what about editing the afform in the GUI. Will the gui have lost track of that reference now that the name changed?

@ufundo ufundo force-pushed the custom-group-tabsets branch 2 times, most recently from b818207 to 1bac07c Compare December 16, 2024 20:09
@ufundo
Copy link
Contributor Author

ufundo commented Dec 16, 2024

Ok, and what about editing the afform in the GUI. Will the gui have lost track of that reference now that the name changed?

Good question. I did look at that briefly and I don't really understand how it works.

GUI seems to recognise options.entity_id and options.contact_id in the markup as references to "Current Contact" :

image

image

Though I don't quite know how it does that?

(Note: the GUI never likes that status_id.is_current_member filter)

@ufundo
Copy link
Contributor Author

ufundo commented Dec 16, 2024

Noticed an issue with the View links for the individual Custom records -- these are still using a QuickForm that is hard-coded for contact

@ufundo
Copy link
Contributor Author

ufundo commented Dec 16, 2024

Issue 2: the event dashboard cleverly creates a quick link to each tab, but these use a subpath rather than a query parameter, and the one for our custom tab doesn't work
image

@ufundo
Copy link
Contributor Author

ufundo commented Dec 16, 2024

c878df0 should fix Issue 2 - it seems fine for the other tabs as well, I'm not really sure why they have dedicated routes?

7092ee0 provides view forms, but maybe a bit heavy duty? I did wonder if there's a way to do something more similar to the afform block on the contact summary?

@colemanw
Copy link
Member

@ufundo provides view forms, but maybe a bit heavy duty?

Seems fine to me :)

@ufundo ufundo force-pushed the custom-group-tabsets branch from 7092ee0 to 5ec170a Compare December 16, 2024 22:00
@ufundo
Copy link
Contributor Author

ufundo commented Dec 16, 2024

I actually thought maybe better to separate out the change to blocks, so have removed in the latest iteration.

Rolled back the test changes for blocks as well.

Fixed the style, and the other failures looked like flakes, so hoping this will pass.

@ufundo
Copy link
Contributor Author

ufundo commented Dec 16, 2024

The other thing I don't like with the view forms: it's only the DisplayOnly meta at the field level that is stopping you from editing data. It feels like it should be a control at the form level. It would be nice to have an afform mode that is like "this form can prefill data, but not submit". Then you could re-use the Update form (and the afblock), but with that "read-only" toggled.

I'd thought of something like that before on the front-end could be neat. User could load the form as read-only, and all the fields are disabled; then (if allowed for that form) they toggle to edit mode, without having to refetch all the data. I guess it would be a bit closer in UX to quickform blocks on the contact summary.

That's a chunk more work though, so maybe the approach here is good enough for now?

@colemanw
Copy link
Member

@ufundo still looking at a failure in testAfformContactSummaryBlock

@colemanw
Copy link
Member

@ufundo I agree that the ability to toggle 'readonly' at the form level would be a great feature! Not a blocker to this PR but a very good idea.

@ufundo ufundo force-pushed the custom-group-tabsets branch from 5ec170a to 7d51ae3 Compare December 17, 2024 07:56
@ufundo ufundo marked this pull request as ready for review December 17, 2024 07:56
@ufundo
Copy link
Contributor Author

ufundo commented Dec 17, 2024

retest this please

@ufundo
Copy link
Contributor Author

ufundo commented Dec 17, 2024

The remaining test fail seems to be common across all open PRs at the moment => think unrelated

@@ -0,0 +1,2 @@
{assign 'options' ['entity_id' => $eventId]}
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is Smarty2-compatible syntax. Also the file needs a trailing newline.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh this file has crept back in during rebase I think. it shouldnt be there/used

@ufundo ufundo force-pushed the custom-group-tabsets branch from 7d51ae3 to 9364b0d Compare December 17, 2024 14:13
@@ -116,9 +116,14 @@
</ul>

{foreach from=$allTabs item=tabValue}
{if !empty($tabValue.template)}
{if $tabValue.template}
Copy link
Member

Choose a reason for hiding this comment

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

Might this cause an undefined index warning? I think you're right we're not supposed to use empty() in templates but maybe we should use isset() to prevent the e-notice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but maybe should have changed the other way or changed both to isset?

@@ -29,7 +29,12 @@
{foreach from=$tabHeader key=tabName item=tabValue}
{if $tabValue.template}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@colemanw I just updated for consistency with here. I added empty to the bit below to avoid an ENOTICE, so maybe it is good to use for both? Or is isset preferable?

Copy link
Member

Choose a reason for hiding this comment

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

IIRC empty() is not compatible with smarty escaping so it's better to use isset(). I think? Might wanna double check what other templates are doing these days.

Copy link
Contributor Author

@ufundo ufundo Dec 19, 2024

Choose a reason for hiding this comment

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

https://docs.civicrm.org/dev/en/latest/security/outputs/#gotcha-2-smarty-notices

isset = BAD
empty = not great

preferred option is make sure the variable is assigned before the template layer but given the number of places assign('tabHeader', $someVar) happens that looks non trivial and we have a function for that! addExpectedTabHeaderKeys here we come :)

@ufundo ufundo force-pushed the custom-group-tabsets branch from 9364b0d to b985d82 Compare December 19, 2024 13:58
@colemanw colemanw added the merge ready PR will be merged after a few days if there are no objections label Dec 19, 2024
@colemanw
Copy link
Member

This all looks merge-ready to me! Good work @ufundo

@ufundo
Copy link
Contributor Author

ufundo commented Dec 19, 2024

This should fix the Smarty unassigned var error: #31636

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
master merge ready PR will be merged after a few days if there are no objections
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants