-
-
Notifications
You must be signed in to change notification settings - Fork 824
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
Towards rationalising settings form & preferences form (partial of 12731) #12732
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
/* | ||
+--------------------------------------------------------------------+ | ||
| CiviCRM version 5 | | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC (c) 2004-2018 | | ||
+--------------------------------------------------------------------+ | ||
| This file is a part of CiviCRM. | | ||
| | | ||
| CiviCRM is free software; you can copy, modify, and distribute it | | ||
| under the terms of the GNU Affero General Public License | | ||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | ||
| | | ||
| CiviCRM is distributed in the hope that it will be useful, but | | ||
| WITHOUT ANY WARRANTY; without even the implied warranty of | | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | ||
| See the GNU Affero General Public License for more details. | | ||
| | | ||
| You should have received a copy of the GNU Affero General Public | | ||
| License and the CiviCRM Licensing Exception along | | ||
| with this program; if not, contact CiviCRM LLC | | ||
| at info[AT]civicrm[DOT]org. If you have questions about the | | ||
| GNU Affero General Public License or the licensing of CiviCRM, | | ||
| see the CiviCRM license FAQ at http://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
/** | ||
* | ||
* @package CRM | ||
* @copyright CiviCRM LLC (c) 2004-2018 | ||
*/ | ||
|
||
/** | ||
* This trait allows us to consolidate Preferences & Settings forms. | ||
* | ||
* It is intended mostly as part of a refactoring process to get rid of having 2. | ||
*/ | ||
trait CRM_Admin_Form_SettingTrait { | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $settingsMetadata; | ||
|
||
/** | ||
* Get default entity. | ||
* | ||
* @return string | ||
*/ | ||
public function getDefaultEntity() { | ||
return 'Setting'; | ||
} | ||
|
||
/** | ||
* Get the metadata relating to the settings on the form, ordered by the keys in $this->_settings. | ||
* | ||
* @return array | ||
*/ | ||
protected function getSettingsMetaData() { | ||
if (empty($this->settingsMetadata)) { | ||
$allSettingMetaData = civicrm_api3('setting', 'getfields', []); | ||
$this->settingsMetadata = array_intersect_key($allSettingMetaData['values'], $this->_settings); | ||
// This array_merge re-orders to the key order of $this->_settings. | ||
$this->settingsMetadata = array_merge($this->_settings, $this->settingsMetadata); | ||
} | ||
return $this->settingsMetadata; | ||
} | ||
|
||
/** | ||
* Get the settings which can be stored based on metadata. | ||
* | ||
* @param array $params | ||
* @return array | ||
*/ | ||
protected function getSettingsToSetByMetadata($params) { | ||
return array_intersect_key($params, $this->_settings); | ||
} | ||
|
||
/** | ||
* @param $params | ||
*/ | ||
protected function filterParamsSetByMetadata(&$params) { | ||
foreach ($this->getSettingsToSetByMetadata($params) as $setting => $settingGroup) { | ||
//@todo array_diff this | ||
unset($params[$setting]); | ||
} | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
moved to the trait