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

core#1132 - don't fire hook_civicrm_fieldOptions before hook_civicrm_… #19580

Merged
merged 1 commit into from
Mar 4, 2021

Conversation

MegaphoneJon
Copy link
Contributor

@MegaphoneJon MegaphoneJon commented Feb 10, 2021

…config loads all files

https://lab.civicrm.org/dev/core/-/issues/1132

Overview

hook_civicrm_config is responsible for adding files to the autoloader. hook_civicrm_config calls hook_civicrm_fieldOptions. As a result, hook_civicrm_fieldOptions crashes if you reference a class that's not in core (i.e. in an extension).

Before

Crashes.

After

No crashes.

Technical Details

The backtrace is on https://lab.civicrm.org/dev/core/-/issues/1132, which explains why this happens.

Comments

This will hopefully fix the conflict that Mosaico 2.6 has with other extensions (like Areas).

Steps to replicate

  • Create a new extension.
  • Create a method on a class in that extension. Here's an example:
<?php

class CRM_Contribute_BAO_PaymentMethodByDomain {

  public static function getPaymentInstrument() {
    return TRUE;
  }

}
  • In hook_civicrm_fieldOptions, call this method.
    At this point, most of CiviCRM will be broken. Clearing cache will certainly trigger the bug.

@civibot
Copy link

civibot bot commented Feb 10, 2021

(Standard links)

@seamuslee001
Copy link
Contributor

So this would mean that extensions can't modify using the buildOptions Hook the list of available languages but I think that is an ok thing In my opinion ping @mlutfy @haystack @mattwire

@MegaphoneJon
Copy link
Contributor Author

@seamuslee001 true. I wrote this mostly as a way to get some more knowledgeable eyes on the bug. If someone tells me this is the right general approach, I'll deal with test failures etc., but I'm not very confident this is the correct fix.

@mlutfy
Copy link
Member

mlutfy commented Feb 11, 2021

I'm OK with not being able to modify the list of languages via fieldOptions().

I've also encountered something similar on some niche configurations (emailapi + multilingual + symbiotic's monitoring extension, which does setLocale calls to make sure that the system supports all enabled translations with native gettext).

I can't comment on the other technical issues around it, but it would definitely need a code comment to avoid regressions :)

@MegaphoneJon
Copy link
Contributor Author

I'll consider @mlutfy's comments to be a preliminary "concept approved", so I'll fix the issues present in this patch.

@eileenmcnaughton
Copy link
Contributor

@mlutfy do you want to give this some light testing - it seems as agreed

@alifrumin
Copy link
Contributor

I ran into veda-consulting-company/uk.co.vedaconsulting.mosaico#427 and this patch fixed it! Thanks @MegaphoneJon

@colemanw
Copy link
Member

colemanw commented Mar 4, 2021

I think this probably should have gotten merged into the RC if it's fixing hard crashes. Anyone object to changing the base for this PR to the RC branch?

@eileenmcnaughton
Copy link
Contributor

I'm happy with this going into the rc

@MegaphoneJon
Copy link
Contributor Author

Now this is against the RC.

@colemanw colemanw merged commit 00037f1 into civicrm:5.36 Mar 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants