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

[REF] Move entityRef filters into their respective BAOs #13625

Merged
merged 1 commit into from
Feb 17, 2019

Conversation

colemanw
Copy link
Member

Overview

Fixes an old FIXME in the code by moving entityRef filters into a more logical place.

Before

Code all jammed into an illogical place.

After

Code in a better place. More future-proof and extensible.

Technical Details

New entities (including entities from extensions) can now declare entityRef filters simply by placing them in their BAO class.

Comments

This is the beginning of a larger cleanup/refactor.

if (class_exists($baoName)) {
$entityFilters = $baoName::getEntityRefFilters();
if ($entityFilters) {
$filters[_civicrm_api_get_entity_name_from_camel($entity)] = $entityFilters;
Copy link
Contributor

Choose a reason for hiding this comment

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

if we are calling this helper function from outside the api I think we should move it to CRM_Core_DAO_AllCoreTables

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry what should be moved?

Copy link
Contributor

Choose a reason for hiding this comment

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

the internal api function

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd prefer to keep it like this for this iteration as the final refactor will not require this function anymore. The plan is to standardize EntityRef fields on the CamelCase entity name as the lowercase names are deprecated as of Api v4.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

*
* @return array
*/
public static function getEntityRefFilters() {
$filters = array();
$config = CRM_Core_Config::singleton();

if (in_array('CiviEvent', $config->enableComponents)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add in some caching - Civi::cache()-> get & set is preferred I believe - this could be doing a bit of php iteration to check all DAOs that exist

Copy link
Member Author

Choose a reason for hiding this comment

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

The output of this function gets cached in the browser - it's part of the l10n.js dynamic script.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK - I guess that's fine it it's also never loaded in batch processes

@eileenmcnaughton
Copy link
Contributor

So I've gone through & recreated this & am pretty confident on the line by line. The other comment I have is that I feel it would be cleaner (and save one query) to have a function on the BAO for isEnabled & have the BAO early return if they are not enabled - this seems like something that could be used in other types of DAO iterations too

@colemanw
Copy link
Member Author

Test fail unrelated.

@colemanw
Copy link
Member Author

@eileenmcnaughton that's a good suggestion and I'd like to think about how to best implement that. One option would be to add a function to AllCoreTables that returns only entities of enabled components. Or we could add a function to CRM_Core_DAO that uses magic static properties to figure out if the called class belongs to an enabled component using string comparison logic like I've done here.

In the meantime I want to keep going with my refactoring work so could we please merge this first (this PR was intended to be a fairly easy to review "simple" refactor -- the more tricky stuff comes later).

@eileenmcnaughton
Copy link
Contributor

Ok - I'll let that lie :-)

@eileenmcnaughton eileenmcnaughton merged commit 063b55b into civicrm:master Feb 17, 2019
@eileenmcnaughton eileenmcnaughton deleted the entityRefs branch February 17, 2019 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants