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#5654 add support for tagging Afforms using Tag entity #31890

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

Conversation

ufundo
Copy link
Contributor

@ufundo ufundo commented Jan 27, 2025

Overview

Adds the ability to tag afforms with Tags (from civicrm_tag table).

Alternative to #31889

Before

  • no tagging for Afforms

After

Technical Details

This implementation uses the civicrm_tag table.

The advantage over #31889 is we have a nice UI for managing tags, and tags can be reused (e.g. for activities and forms)

On the flipside, this might be a slightly deviant usage of tags, because the used_for field generally expects a table name in order to create db table joins between tagged entities and tags, using the EntityTag bridge (with a dynamic FK entity_table and entity_id). In this case Afform is not a db entity, so cannot be referenced in this way - the values are just being loaded into a pseudoconstant, and then serialized in the Afform meta.

However - I feel like this might be legitimate for tags in an Api4 world - ie the key thing for tags is they reference an entity. If this is a DB entity then great, we get stuff for handling the DB queries out of the box. If not there is a bit more flexibility/work to do in how a BasicEntity uses the tags.

Copy link

civibot bot commented Jan 27, 2025

🤖 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 Jan 27, 2025
@ufundo
Copy link
Contributor Author

ufundo commented Jan 27, 2025

I think this is my preferred approach over #31889 but interested in other views

@ufundo
Copy link
Contributor Author

ufundo commented Jan 27, 2025

As a next step, I would have liked to switch the input on the FormBuilder screen to a crm-autocomplete with a QuickAdd form popup ( using /civicrm/tag/edit?action=add&used_for=Afform )

But that wasn't working for some reason. I think there may be a constraint where Quick Add forms must have 'quick-add' in their url path. @colemanw are you aware of that?

In general one of the reasons I prefer this approach is I think the UI could improve over time if we add more Tag support to SearchKit / FormBuilder (i.e. things like correctly coloured swatches in the SearchKit listing and type-to-create-new-tags-on-the-fly ).

@colemanw
Copy link
Member

@ufundo I feel pretty good about this deviant use of the Tag entity. I vote for this option!

@ufundo ufundo force-pushed the afform-tags-using-entity branch from 0920a6b to 434ab6f Compare January 27, 2025 21:52
@ufundo ufundo marked this pull request as ready for review January 27, 2025 21:53
@ufundo
Copy link
Contributor Author

ufundo commented Jan 27, 2025

@ufundo I feel pretty good about this deviant use of the Tag entity. I vote for this option!

I was slightly wary the schema builder might blow up somewhere because of the not-physical-table-name in used_for but haven't seen that locally, and tests seem to pass, so maybe this is ok?

@colemanw
Copy link
Member

I was slightly wary the schema builder might blow up somewhere because of the not-physical-table-name in used_for but haven't seen that locally, and tests seem to pass, so maybe this is ok?

@ufundo I have an idea of how to pre-empt anybody attempting to use these in the EntityTag table. Just pushed 4f9ab8d

Comment on lines 11 to 13
// - creates an example tag that can be used for afforms. This is more to demonstrate
// how it can be used, as Donor Journey might be useful for some orgs but not for others
// @todo think of better example tag that is more universally applicable?
Copy link
Member

Choose a reason for hiding this comment

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

I think it's better not.

As a general principle I think we should not install sample data onto people's sites unless they specifically select the "sample data" option in the installer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

General principle: definitely agree.

My worry here though is that the "Used For" on Tags isn't discoverable enough, so people might not find how to add tags that they can use here, so I thought this might be a reasonable exception to the rule. (Note we add example Tags by default on new installs. Also Tags are by their nature very easy to throw away, so it feels not such an imposition to add this one?)

But I don't mind, can remove if you're not convinced.

Copy link
Member

Choose a reason for hiding this comment

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

Yea, I had the same concern when I added tagging to SearchKit, so my solution was to create the select-or-create tag widget inspired by GitHub tags (try tagging a searchKit, it's cool).
We could probably extract that widget from SearchKit and reuse it here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ooh, yes please. Then I can use it in civirules as well...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ooh I hadn't seen that before. Definitely a useful widget! For formbuilder too please 😉

Component will definitely need a bit of refactoring because the component is using EntityTag api... but would be great definitely. Happy to remove this in the meantime

(Slightly separate point - I find different orgs have different policies on whether inline tag creation is a useful feature or makes it too easy for thousands of unhelpful tags to proliferate. So might be good if there was some way to configure that... At the moment for quickform tag widgets it seems to vary a bit on different screens...)

@@ -26,7 +26,7 @@
'label' => E::ts('Afforms'),
'is_reserved' => TRUE,
'is_active' => TRUE,
'domain_id' => NULL,
'filter' => 1,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is filter normally used for ?

Copy link
Member

Choose a reason for hiding this comment

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

Not much of anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could it have a more semantic value? Like filter = 'tableless' and then the condition != tableless?

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 the table column is an int.. so no

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added a comment for the significance

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And removed the example tag

@ufundo
Copy link
Contributor Author

ufundo commented Jan 28, 2025

Oh weird I didn't see these fails before https://test.civicrm.org/job/CiviCRM-Test/45834/testReport/

@colemanw
Copy link
Member

colemanw commented Jan 28, 2025

@ufundo this ought to fix it: 6ac1f0a

@ufundo
Copy link
Contributor Author

ufundo commented Jan 28, 2025

@ufundo this ought to fix it: d74439b

Looks good! 💪

@colemanw colemanw force-pushed the afform-tags-using-entity branch from d74439b to 6ac1f0a Compare January 28, 2025 18:01
@ufundo ufundo force-pushed the afform-tags-using-entity branch from 6ac1f0a to 4cbc848 Compare January 30, 2025 14:12
@ufundo ufundo changed the title add support for tagging Afforms using Tag entity dev/core#5654 add support for tagging Afforms using Tag entity Jan 30, 2025
@ufundo ufundo force-pushed the afform-tags-using-entity branch from 4cbc848 to b07350d Compare January 30, 2025 15:26
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