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

CRM-20923 refactor tpl to be based on metadata not hard-coding #10704

Merged
merged 2 commits into from
Jul 21, 2017

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Jul 20, 2017

@@ -78,10 +78,11 @@ public function setDefaultValues() {
* Build the form object.
*/
public function buildQuickForm() {
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin', 'reset=1'));

Copy link
Member

Choose a reason for hiding this comment

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

no need for this space

$args = func_get_args();
$check = reset($args);
// does this do anything?
reset($args);
Copy link
Member

Choose a reason for hiding this comment

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

// does this do anything?

no it doesn't , $args function is not used at all so lines from 83 to 85 can be safely removed .

foreach ($this->_settings as $setting => $group) {
$settingMetaData = civicrm_api('setting', 'getfields', array('version' => 3, 'name' => $setting));
$props = $settingMetaData['values'][$setting];
// Getting all once seems better than multiple calls.
Copy link
Member

Choose a reason for hiding this comment

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

this comment doesn't make sense for someone reading the code without looking at the commit history ... the code comments should describe the current version of the code not how it was before and how it get changed... this comment should be removed or replaced with something related .. but I prefer removing it.

$settingMetaData = civicrm_api('setting', 'getfields', array('version' => 3, 'name' => $setting));
$props = $settingMetaData['values'][$setting];
// Getting all once seems better than multiple calls.
$allSettingMetaData = civicrm_api3('setting', 'getfields', array());
Copy link
Member

Choose a reason for hiding this comment

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

probably better for this to move to seperate method :

```php
$settingMetaData = $this->getSettingsMetaData();

```php
/**
* Docblock goes here
*/
private function getSettingsMetaData() {
    $allSettingsMetaData = civicrm_api3('setting', 'getfields', array());

    $settingMetaData = array_intersect_key($allSettingMetaData['values'], $this->_settings);
    // re-ordering the settings to follow $this->_settings order.
    $settingMetaData = array_merge($this->_settings, $settingMetaData);
   
    return $settingMetaData ;
}

$settingMetaData = array_intersect_key($allSettingMetaData['values'], $this->_settings);
// This array_merge re-orders to the key order of $this->_settings.
$settingMetaData = array_merge($this->_settings, $settingMetaData);

Copy link
Member

Choose a reason for hiding this comment

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

better to remove the space since the variables above used in the loop so it make more sense for them to be right before the loop , whole thing would be :

$descriptions = array();
$settingMetaData = $this->getSettingsMetaData();
foreach ($settingMetaData as $setting => $props) {
//etc

// This array_merge re-orders to the key order of $this->_settings.
$settingMetaData = array_merge($this->_settings, $settingMetaData);

foreach ($settingMetaData as $setting => $props) {
Copy link
Member

Choose a reason for hiding this comment

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

actually would be nicer (I think( if you moved the whole loop to another separate private method such buildingSettingFields($settingMetaData) or something like that .. it would make the could much easier to understand

$this->assign('setting_descriptions', $descriptions);
$this->assign('settings', $settingMetaData);
Copy link
Member

Choose a reason for hiding this comment

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

isn't settingFields would be more descriptive name instead of just settings ?

@omarabuhussein
Copy link
Member

omarabuhussein commented Jul 20, 2017

@eileenmcnaughton generally these modifications look fine to me , though left view notes about the code itself ... also can you provide more details in the PR description + ticket to make sure that anyone read it understand what it about without the need to look into the code .

Change-Id: Iee2a7aa9fa93c5d20b95f3dbc45ec2f3cf7a216b
@eileenmcnaughton
Copy link
Contributor Author

I've made the changes you suggested with the exception of the second function extraction. My hesitation there is I really want to get the whole $descriptions array out of that loop & those adhoc rules & feel like extracting makes it easier to ignore those issues next pass through

@eileenmcnaughton
Copy link
Contributor Author

@colemanw -are you able to merge this?

@monishdeb
Copy link
Member

Hmm encountered some style issue.. working on it

@eileenmcnaughton
Copy link
Contributor Author

you mean the green tick doesn't mean it passed?

@monishdeb
Copy link
Member

monishdeb commented Jul 21, 2017

@eileenmcnaughton there was extra { on SettingForm.tpl and other minor changes. I have updated the PR and works fine as expected.

@monishdeb
Copy link
Member

Tested, working fine

@monishdeb monishdeb merged commit fabcf30 into civicrm:master Jul 21, 2017
@monishdeb monishdeb deleted the admin_form branch July 21, 2017 11:02
@eileenmcnaughton
Copy link
Contributor Author

Thanks @monishdeb - clearly a mistake I made in the second round when I decided to move the code into a sharable tpl ! I thought I did check it but obviously not very well!

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.

4 participants