compucorp / uk.co.compucorp.membershipextras

Membership Extras for CiviCRM
Other
5 stars 8 forks source link

CIWEMB-535: Hide fields that are unnecessary for payment plans linked to payment schemes #518

Closed omarabuhussein closed 8 months ago

omarabuhussein commented 9 months ago

Overview

In this PR: https://github.com/compucorp/uk.co.compucorp.membershipextras/pull/473 we hid several fields from the recurring contribution view page if it is linked to a payment scheme, here we are doing the same on the recurring contribution edit form.

Before

The recurring contribution "edit" form shows the following fields:

2024-01-31 23_40_36-aokacs acsas _ Site-Install

and when trying to submit the form it shows the following message:

image

After

These fields are now hidden:

2024-01-31 23_36_49-aokacs acsas _ Site-Install

and when trying to submit the form, it no longer mentions the "Cycle day", but rather it shows the same message that appear to "annual" payment plans:

2024-01-31 23_38_10-aokacs acsas _ Site-Install

where recurring contributions that are not linked to a payment scheme still work as they used to where all these fields are visible:

2024-01-31 23_37_29-kadsa@ad com kadsa@ad com _ Site-Install

Technical Details

The "Cycle day" and "Next Scheduled Contribution Date" do not exist on the original CiviCRM recurring contribution form, and they were rather added by us inside the buildForm hook, so hiding both of them was a matter of adding an if condition so they are only added if the edited recurring contribution is linked to a payment scheme.

But because we also have some validations inside the form validation hook related to these two fields and some other stuff we do in the postProcess hook, I also had to also to update these two hooks to ignore these operations in case of payment schemes.

For the "instalments" and the "frequency" fields, and given they are added to the form by CiviCRM core, I had to use Javascript/JQuery to hide them.