Skip to content

Remove dead Task_Register check from setFeeDefaults() - #38305

Merged
colemanw merged 1 commit into
civicrm:masterfrom
Sjord:fix-event-registration-dead-task-register-check
Nov 26, 2026
Merged

colemanw merged 1 commit into
civicrm:masterfrom
Sjord:fix-event-registration-dead-task-register-check

Conversation

@Sjord

@Sjord Sjord commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

in_array is never true, because CRM_Event_Form_Registration does not extend CRM_Event_Form_Task_Register. Remove it.

CRM_Event_Form_Registration::setFeeDefaults() is only called from CRM_Event_Form_Registration_Register and
CRM_Event_Form_Registration_AdditionalParticipant, both subclasses of CRM_Event_Form_Registration. CRM_Event_Form_Task_Register extends CRM_Event_Form_Participant instead, so get_class($this) can never match it here and the in_array() condition is always false.

The check was carried over from the shared EventFees implementation when this function was copied into CRM_Event_Form_Registration, where Participant and Task_Register are valid callers. Removing it preserves the existing behaviour for the front-end registration forms: full options are still not preselected. The equivalent check in CRM_Event_Form_EventFees::setDefaultValues() remains valid and is unchanged.

No behaviour change.

AI disclosure: This contribution was human-driven, written with the AI coding agent DeepSeek V4.1 Flash 1017, human-reviewed.

Overview

in_array is never true, because CRM_Event_Form_Registration does not extend CRM_Event_Form_Task_Register. Remove it.

Before

setFeeDefaults() skipped full price options with a condition that also tried to exempt the task-registration form:

if ($values['is_default']) {
  if (!in_array(get_class($this), ['CRM_Event_Form_Task_Register']) && !empty($values['is_full'])) {
    continue;
  }

The method belongs to CRM_Event_Form_Registration and is only called from CRM_Event_Form_Registration_Register and CRM_Event_Form_Registration_AdditionalParticipant. CRM_Event_Form_Task_Register extends CRM_Event_Form_Participant, not CRM_Event_Form_Registration, so get_class($this) could never equal 'CRM_Event_Form_Task_Register'.

The condition is a leftover from the shared implementation in CRM_Event_Form_EventFees::setDefaultValues(), where it is valid because Participant and Task_Register really are callers:

if (!in_array(get_class($form), ['CRM_Event_Form_Participant', 'CRM_Event_Form_Task_Register']) && !empty($values['is_full'])) {

After

The dead class check is removed and the remaining condition states the actual rule:

if ($values['is_default']) {
  // Front-end registration forms never preselect a full option.
  if (!empty($values['is_full'])) {
    continue;
  }

Technical Details

  • CRM/Event/Form/Registration.php: remove the in_array(get_class($this), ['CRM_Event_Form_Task_Register']) half of the condition in setFeeDefaults().
  • The function was copied into CRM_Event_Form_Registration in commit 7bb311563c (Copy shared function back to online event callers). The original EventFees version listed CRM_Event_Form_Participant and CRM_Event_Form_Task_Register, both of which are valid EventFees callers. When copied into the online-registration base class, only Task_Register was retained, and it is not in that hierarchy.
  • No behaviour change. Before the split, CRM_Event_Form_Registration_Register and CRM_Event_Form_Registration_AdditionalParticipant also skipped full options; the Task_Register clause never applied to them. Front-end forms still do not preselect a sold-out option.
  • The equivalent check in CRM_Event_Form_EventFees::setDefaultValues() remains unchanged because it is valid there.
  • No test is added: this removes unreachable code and does not change behaviour.

Comments

Branch: fix-event-registration-dead-task-register-check
Commit: 76b2891e1b
No schema or API changes.
Static analysis was used to spot the condition; the fix is a dead-code removal, not a response to a CI requirement.
AI disclosure: This contribution was written with the AI coding agent DeepSeek V4.1 Flash 1017 (OpenCode), human-reviewed.

CRM_Event_Form_Registration::setFeeDefaults() is only called from
CRM_Event_Form_Registration_Register and
CRM_Event_Form_Registration_AdditionalParticipant, both subclasses of
CRM_Event_Form_Registration. CRM_Event_Form_Task_Register extends
CRM_Event_Form_Participant instead, so get_class($this) can never match
it here and the in_array() condition is always false.

The check was carried over from the shared EventFees implementation when
this function was copied into CRM_Event_Form_Registration, where
Participant and Task_Register are valid callers. Removing it preserves
the existing behaviour for the front-end registration forms: full
options are still not preselected. The equivalent check in
CRM_Event_Form_EventFees::setDefaultValues() remains valid and is
unchanged.

No behaviour change.

AI disclosure: This contribution was human-driven, written with the AI
coding agent DeepSeek V4.1 Flash 1017, human-reviewed.
@civibot

civibot Bot commented Nov 26, 2026

Copy link
Copy Markdown

🤖 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.
PR commands & links...
  • /rebase <?branch-name> will rebase your branch and change the base of the PR (if <branch-name> is specified).
  • /squash will combine all commits (keeping only the first commit messsage).
  • /port <branch-name> will create a copy of this PR against a different branch.
  • /lint will automatically fix linting errors, amending commits as needed.
  • retest this please will rerun the tests and rebuild the demo site.
  • 📖 Review standards
  • 🗒️ Review template (brief or verbose)

➡️ Online demo of this PR 🔗

@civibot civibot Bot added the master label Nov 26, 2026
@colemanw

Copy link
Copy Markdown
Member

@civireview

@civireview civireview left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CiviReview: 🟢 Ready · 5/5 ★★★★★

Removes an unreachable in_array(get_class($this), ['CRM_Event_Form_Task_Register']) check from CRM_Event_Form_Registration::setFeeDefaults(). Full default price options are still skipped on front-end registration forms.

No findings above the confidence gate.

✅ CI · ✅ Base tests · ✅ Surface

Verification (3 checks, 1 not verified)

Merge confidence (5/5): No verified issues; passed CI / Jenkins, Base-Test Regression, Live Surface Diff.

PR: civicrm/civicrm-core#38305 · Profile: core · Kind: core-bugfix · Commits: f2fba12 → 76b2891

Check Status Detail
CI / Jenkins ✅ PASS 1 CI checks: 1 passed, 0 failed, 0 pending.
Base-Test Regression ✅ PASS 62 test(s) passed on A and B
Live Surface Diff ✅ PASS Live APIv4/APIv3/routes/Afform surface diff captured with 0 risk flags.

Not verified:

  • No added/modified PHPUnit tests in PR; Proof-of-Fix A/B test skipped.
More: Walkthrough · blast radius

Walkthrough

  • CONFIRMED: CRM_Event_Form_Task_Register extends CRM_Event_Form_Participant (CRM/Event/Form/Task/Register.php:26), and CRM_Event_Form_Registration extends CRM_Core_Form (CRM/Event/Form/Registration.php:22). get_class($this) inside setFeeDefaults() therefore can never be 'CRM_Event_Form_Task_Register', so the removed !in_array(...) check was always true.
  • CONFIRMED: the only callers of setFeeDefaults() (protected, defined at Registration.php:2304) are Registration/Register.php:230 and Registration/AdditionalParticipant.php:142. Both are subclasses of CRM_Event_Form_Registration. The simpler !empty($values['is_full']) check at Registration.php:2363 gives the same result as before. An extension subclass also cannot be named CRM_Event_Form_Task_Register, because that class name already belongs to core.
  • CONFIRMED: the diff changes one file, +2/-1. It removes the dead clause and adds a comment. There are no schema, API, template or behaviour changes.
  • PROVEN: the CiviKitchen A/B base-test-regression run passed all 62 Event form tests on both A and B, with no regressions. Jenkins passed 1 of 1 checks.
  • No test was added, so the Proof-of-Fix A/B run was skipped. That is fine here: the change removes unreachable code and has no observable behaviour to test.

Ecosystem blast radius

Repo Path Symbol Impact
civicrm-core CRM/Event/Form/Registration/Register.php CRM_Event_Form_Registration_Register::setDefaultValues Calls setFeeDefaults(); full options are still never preselected, so behaviour is unchanged.
civicrm-core CRM/Event/Form/Registration/AdditionalParticipant.php CRM_Event_Form_Registration_AdditionalParticipant::setDefaultValues Calls setFeeDefaults(); behaviour is unchanged.

Automated AI-assisted review, alpha: it may miss issues or report false positives, so verify findings before acting and open an issue with feedback. Reviewed by civireview · sonnet-opus · 199,823 tokens · $0.26

@colemanw

Copy link
Copy Markdown
Member

I agree it's unreachable. Thanks @Sjord

@colemanw
colemanw merged commit 2a0c1c8 into civicrm:master Nov 26, 2026
1 check passed
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