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] CustomField code cleanup #16968

Merged
merged 2 commits into from
Apr 7, 2020
Merged

Conversation

colemanw
Copy link
Member

@colemanw colemanw commented Apr 3, 2020

Overview

This is some initial code cleanup and refactoring to make CustomFields a bit more consistent.
I'm trying to standardize on using the isSerialized method rather than ad-hoc guesswork based on the html_type.

@civibot
Copy link

civibot bot commented Apr 3, 2020

(Standard links)

@civibot civibot bot added the master label Apr 3, 2020
'AdvMulti-Select',
])
) {
if (is_array($fieldValue) && $this->_fields[$name][$fieldName]['html_type'] == 'CheckBox') {
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 history of this section of code is murky but from what I can tell, this is applying special formatting to checkboxes.
So instead of a double-negative conditional "not field types that are not checkbox" let's just say "if checkbox".
Perhaps @monishdeb can confirm this as the git history suggests he was involved writing this originally.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for this

Copy link
Contributor

Choose a reason for hiding this comment

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

so it looks like possible html types are

'CheckBox':
'Multi-Select':
'Multi-Select State/Province':
'Multi-Select Country':
'Select':
'Autocomplete-Select':
'Radio':
'Select Country':
'Select State/Province':
''Select Date'
'File'
'Link'
'Text Area'
'Text'

To validate this we need to confirm that only the top 4 could be arrays at this point

Copy link
Member Author

Choose a reason for hiding this comment

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

@eileenmcnaughton so the two ways of writing and evaluating a refactor would be (roughly):

  1. The code analysis approach: Analyze the original code and figure out what it does based on all possible inputs. Make sure the refactored code behaves exactly the same in all circumstances.
  2. The "what were they thinking?" approach: Guess what the developer was trying to accomplish (which may not match what the code actually says because developers are only human). Make sure the refactored code satisfies their intentions.

I'm going with number 2, because based on the context (and basically the same code being duplicated in many other places) that this block is for the sake of checkboxes only, even though that's not exactly what it said.

@colemanw
Copy link
Member Author

colemanw commented Apr 3, 2020

retest this please

colemanw added 2 commits April 5, 2020 08:49
The history of this section of code is murky but from what I can tell,
this is applying special formatting to checkboxes. So instead of a double-negative conditional
"not field types that are not checkbox" let's just say "if checkbox".
@pradpnayak
Copy link
Contributor

Tested, works fine. good to merge!

@colemanw colemanw merged commit 669974b into civicrm:master Apr 7, 2020
@colemanw colemanw deleted the multi-cleanup branch April 7, 2020 15:53
@eileenmcnaughton
Copy link
Contributor

I'm happy with this merge based on @pradpnayak's testing

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