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

Configure Event Fees tab #25120

Merged
merged 6 commits into from
Dec 18, 2022
Merged

Conversation

brienneK
Copy link
Contributor

@brienneK brienneK commented Dec 6, 2022

Overview

This PR makes the Fees tab on the Configure Event page - as well as the link to the Fees page from the Configure button on an event - conditionally dependent on whether CiviContribute is enabled. This will prevent users from trying to set up a paid event when the Component that allows payment processing is not active.

Before

Previously, if the CiviContribute Component was disabled, the Configure Event page included the Fees tab, which would allow users to try to set up a paid event. However, users would receive an error because without CiviContribute, there are no Financial Types for a user to select from.

Selection_156

Selection_157

Selection_158

After

With this PR, the Fees tab and its corresponding link on the Configure menu of an event are not displayed if CiviContribute is disabled. (CiviContribute can be disabled by going to Administer > System Settings > Components, unchecking the box next to the component's name, and clicking Save.)

Selection_154

Selection_155

Technical Details

While ideally one shouldn't repeat themselves in code, since the code that controls the tab and the link are housed in two different classes, I made the same changes to both files; wrapping the line(s) of code that generate the Fees tab/link in an if block that is only entered if CiviComponent is within the ['value'] array returned by an APIv4 call to the enable_components Setting entity.

@civibot
Copy link

civibot bot commented Dec 6, 2022

(Standard links)

@civibot civibot bot added the master label Dec 6, 2022
@demeritcowboy
Copy link
Contributor

jenkins retest this please.

@demeritcowboy
Copy link
Contributor

jenkins retest this please

@@ -66,7 +66,14 @@ public static function process(&$form) {
$tabs = [];
$tabs['settings'] = ['title' => ts('Info and Settings'), 'class' => 'ajaxForm livePage'] + $default;
$tabs['location'] = ['title' => ts('Event Location')] + $default;
$tabs['fee'] = ['title' => ts('Fees')] + $default;
// Check to see if CiviContribute is an enabled component.
$components = \Civi\Api4\Setting::get()
Copy link
Contributor

Choose a reason for hiding this comment

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

The helper Civi::settings()->get('enable_components') is a little pithier (we also support that for extensions/outside core)

->addSelect('enable_components')
->execute()[0]['value'];
// If CiviContribute is active, create the Fees tab.
if (in_array('CiviContribute', $components)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually - even pithier....
if (CRM_Core_Component::isEnabled('CiviContribute')) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you @eileenmcnaughton - that is much pithier! I've modified the code to use that helper instead of the API call to achieve the conditional logic.

@eileenmcnaughton
Copy link
Contributor

Code makes sense - there is a helper if (CRM_Core_Component::isEnabled('CiviContribute')) { that would make it more concise

@eileenmcnaughton eileenmcnaughton merged commit 38a7d7a into civicrm:master Dec 18, 2022
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