-
Notifications
You must be signed in to change notification settings - Fork 48
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
PCHR-3544: Hide Fields for Contact Summary #2703
PCHR-3544: Hide Fields for Contact Summary #2703
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall, some minor changes
*/ | ||
public function upgrade_1022() { | ||
$valuesRemoved = $this->up1022_getContactEditOptionValues(); | ||
$optionValues = $this->up1022_getActiveContactEditOptionValues(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's quite confusing with OptionValue.value
but maybe we could make the naming a bit clearer here?
In the end we want to do a diff of "values to remove" and "active values" and only remove those that we want to that are not active, right? $valuesRemoved
sounds like they have already been removed, and $optionValues
is a bit vague about which option values they are.
What do you think about renaming $valuesRemoved
to $valuesToRemove
and up1022_getContactEditOptionValues
to up1022_getContactEditOptionValuesToRemove
?
And then renaming $optionValues
to $activeOptionValues
. We could then keep the variable $valuesToRemove
and reassign it with the result of the diff, because really these are the "values we will remove"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted thanks.
'return' => ['contact_edit_options'], | ||
]); | ||
|
||
return $result['values'][0]['contact_edit_options']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just a personal preference, but I like removing sequential
and using array_shift on the result instead, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth exploring. My main idea behind sequential is using it whenever i do not care about iterating over entity id. By not using sequential, results will be indexed their ids
and not array index.
trait CRM_HRCore_Upgrader_Steps_1022 { | ||
|
||
/** | ||
* Hide Fields For Contact Summary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing @return
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed thanks
$names = $this->up1022_getUnusedContactEditOptionNames(); | ||
|
||
$params = [ | ||
'sequential' => 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is sequential
required here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By using sequential, i did not have to worry myself with the key in my foreach
foreach ($optionValues['values'] as $optionValue) {
Like you said, i think its just preference.
|
||
foreach (['Contact', 'IM', 'Website'] as $name) { | ||
$params = ['return' => ['id']]; | ||
if ($name == 'Contact') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use ===
here
|
||
$result = civicrm_api3($name, 'get', $params); | ||
if ($result['count'] == 0) { | ||
array_push($names, $name == 'Contact' ? 'Suffix' : $name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
===
should be fine here too
/** | ||
* Hide Fields For Contact Summary | ||
*/ | ||
public function upgrade_1022() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a general question, if this upgrader is run twice will the result be the same? That's what we aim for with upgraders. I think this one looks fine, but just asking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a benefit of doubt, i tested with running the upgrade twice by changing the schema_version
on civicrm_extension
for HR Core
backward and running drush cvapi extension.upgrade
. The results remains the same. This was made possible by $activeOptionValues = array_diff($optionValues, $valuesRemoved);
which will always return same result after upgrade.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks a lot for checking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good ⚡
/** | ||
* Hide Fields For Contact Summary | ||
*/ | ||
public function upgrade_1022() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks a lot for checking
'return' => ['contact_edit_options'], | ||
]); | ||
|
||
return $result['values'][0]['contact_edit_options']; | ||
return $result['values'][$result['id']]['contact_edit_options']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, that's a good approach too
8384336
to
f3b4a6f
Compare
Overview
Some contact summary fields are visible by default. This PR changes the default for Suffix, Instant messenger and Social Accounts to un-check so they are hidden from users by default
Before
After
Technical Details
Before un-checking the fields, it was ensured that no record previously existed relating to them.
They are also compared against previously activated fields. This implies that they are ignored if not previously checked.